简体   繁体   中英

PHP CURL file upload being saved to Sharepoint instead of OneDrive

I've come across a really weird (and a little alarming) problem.

  1. I'm using Microsoft's sample users to test my integration - in this case Diego Siciliani
  2. I'm using a File Type input to pass FormData to PHP via Ajax
  3. The file upload gets saved to the organisation's shared folders in Sharepoint , instead of a specific personal folder in the user's OneDrive .

Here's my CURL:

    $filename = $_FILES['file']['name'];

    $headers = array(
        "Authorization: Bearer " . $token, 
        "Host: graph.microsoft.com",
        "Content-Type: application/json",
        "Content-Length: 0",
    );

    $postfile = curl_init('https://graph.microsoft.com/v1.0/' . $userid . '/drive/root:/{folder}/' . $filename . ':/content'); 
    curl_setopt($postfile, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($postfile, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($postfile, CURLOPT_FOLLOWLOCATION, 1); 
    $result = curl_exec($postfile); 
    curl_close($postfile); 

This is what OneDrive looks like immediately after: 在此处输入图像描述

And this is what Sharepoint looks like immediately after: 在此处输入图像描述

Anyone know why this is happening?

There is a slight correction you will have to do.

The endpoint you are using

https://graph.microsoft.com/v1.0/<userid>/drive/....

Will return only the root sharepoint Drive.

If you would like to use get the OneDrive URL other's person or your OneDrive you will have to use the below.

To access a specific user's one drive

https://graph.microsoft.com/v1.0/users/<userid>/drive/...

To access yours, you could the below

https://graph.microsoft.com/v1.0/me/drive/...

To access a specific users drive => ...v1.0/users/<userid>/... instead of ...v1.0/<userid>/....

Note: You will need additional permission if you are accessing other person's onedrive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM