vgrem / phpSPO

Microsoft 365 Library for PHP.
MIT License
355 stars 115 forks source link

PHPSPO Access to root folder for Personal Onedrive using plain credentials #296

Open fvfv opened 1 year ago

fvfv commented 1 year ago

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;

}
zenichanin commented 1 year ago

@fvfv were you able to figure this out? I've been trying sharepoint API but can't access files (excel) so I think it's actually on onedrive instead but I have not been able to get it working either.

The file URL is something like:

https://xxxxx-my.sharepoint.com/:x:/g/personal/xxxx_xxxxx_onmicrosoft_com/xxxxxxxxx

So far I've tried using https://xxxxx-my.sharepoint.com as site url and then tried getFileById and getFileByServerRelativeUrl but it always shows file not found.

adgsoluciones commented 6 months ago

Is it possible to get or upload files without admin rights, I mean, I just have useraccount (my emailaddress) and password and I'm a simple user that open OneDrive or SP authenticating by Microsoft.