PHP CURL 文件上传保存到 Sharepoint 而不是 OneDrive
PHP CURL file upload being saved to Sharepoint instead of OneDrive
我遇到了一个非常奇怪(而且有点令人担忧)的问题。
- 我正在使用 Microsoft 的示例用户来测试我的集成 - 在此
案例 Diego Siciliani
- 我正在使用文件类型输入通过 Ajax
将 FormData 传递给 PHP
- 文件上传保存到 Sharepoint 中的组织共享文件夹,而不是用户 OneDrive 中的特定个人文件夹。
这是我的 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);
这是 OneDrive 之后的样子:
这就是 Sharepoint 之后的样子:
有人知道为什么会这样吗?
您需要稍作更正。
您正在使用的端点
https://graph.microsoft.com/v1.0/<userid>/drive/....
请问return只有root sharepoint Drive。
如果您想使用获取 OneDrive URL 其他人或您的 OneDrive,则必须使用以下内容。
访问特定用户的一个驱动器
https://graph.microsoft.com/v1.0/users/<userid>/drive/...
要访问您的,您可以执行以下操作
https://graph.microsoft.com/v1.0/me/drive/...
访问特定用户驱动器 => ...v1.0/users/<userid>/...
而不是 ...v1.0/<userid>/....
注:
如果您要访问其他人的 onedrive,您将需要额外的权限。
我遇到了一个非常奇怪(而且有点令人担忧)的问题。
- 我正在使用 Microsoft 的示例用户来测试我的集成 - 在此 案例 Diego Siciliani
- 我正在使用文件类型输入通过 Ajax 将 FormData 传递给 PHP
- 文件上传保存到 Sharepoint 中的组织共享文件夹,而不是用户 OneDrive 中的特定个人文件夹。
这是我的 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);
这是 OneDrive 之后的样子:
这就是 Sharepoint 之后的样子:
有人知道为什么会这样吗?
您需要稍作更正。
您正在使用的端点
https://graph.microsoft.com/v1.0/<userid>/drive/....
请问return只有root sharepoint Drive。
如果您想使用获取 OneDrive URL 其他人或您的 OneDrive,则必须使用以下内容。
访问特定用户的一个驱动器
https://graph.microsoft.com/v1.0/users/<userid>/drive/...
要访问您的,您可以执行以下操作
https://graph.microsoft.com/v1.0/me/drive/...
访问特定用户驱动器 => ...v1.0/users/<userid>/...
而不是 ...v1.0/<userid>/....
注: 如果您要访问其他人的 onedrive,您将需要额外的权限。