Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fvfv opened this issue Oct 3, 2022 · 2 comments
Open
Labels

Comments

@fvfv
Copy link

fvfv commented Oct 3, 2022

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;


}
@vgrem vgrem added the question label Oct 5, 2022
@zenichanin
Copy link

@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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants