phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

PHPSPO Access to root folder for Personal Onedrive using plain credentials

Open fvfv opened this issue 1 year ago • 2 comments

Thanks for the library. Works amazing for sharepoint sites. However for Personal Onedrive for business is where I'm getting stuck at,.

The thing I like about using SPO is that it does not require admin consent and scopes to generate a token, SPO allows you to send userid and password and as long as the creator of the Sharepoint site or OneDrive for business gives you rights, I can automate sending and retrieving files.

the onedrive personal site is https://[mycompanyHere]-my.sharepoint.com/personal/[user Here]

On sharepoint, to get to the root folder, I jiust send "/sites/[MyCompanySharePointName] and I can create folders or download files once i pass that to getFolderByServerRelativeURL();

On Onedrive, I am unable to specify a root folder, no matter what I put on the function getFolderByServerRelativeUrl();

I have Tried "Documents", "/Documents" , "FolderNameAsAppearsOnTheWeb", etc and I am unable to create a folder or list files.

Really appreciate your help

This is my code: $this->client is generated by $this->client = (new ClientContext($siteURL))->withCredentials($credentials);

function listItems2 ($sourceFileUrl) { $files = []; $client = $this->client;

    $rootFolder = $client->getWeb()->getFolderByServerRelativeUrl($sourceFileUrl)->executeQuery();
    debug ($rootFolder->getServerRelativeUrl());
    
    /** @var File $file */
    foreach ($rootFolder as $file) {
        $files[] = $file->getServerRelativeUrl();
    }
    
    sort ($files);
    return $files;


}

fvfv avatar Oct 03 '22 19:10 fvfv