How to retreive / download content of a shered oneDrive in SharePoint url

  api, onedrive, php, sharepoint

I am trying to retrieve the contents of shared Onedrive folders on Sharepoint sites for clients.
In php with Guzzle I call the OneDrive api and the user token:

https://api.onedrive.com/v1.0/shares/{TOKEN}/root?expand=children

then I retrieve the content like this:

$token = "****";
$url = preg_replace("/{TOKEN}/", $token, "https://api.onedrive.com/v1.0/shares/{TOKEN}/root?expand=children");

try {
    $res = $client->request("GET", $url, ["headers" => ["Content-Type" => "application/json"]]);
  } catch (ClientException $exception) {
    return null;
  }

$decoded = json_decode($res->getBody()->getContents(), true);

But I don’t know how to do it with sharePoint url like:

https://{company_sharepoint_domain}.sharepoint.com/personal/{user_name_id}/_layouts/15/onedrive.aspx

I have the client_id and secret but can’t find a solution.
I’m looking for a complete example if it’s possible.

Source: Ask PHP

LEAVE A COMMENT