出于某种奇怪的原因,我无法使用 MS Graph API 在驱动器中上传文件或创建文件夹。我可以查看/列出甚至删除,没有任何问题。个人 OneDrive 文件也是如此……我可以列出和删除,但不能上传或创建文件夹。我什至无法创建上传会话。据我所知,我已经正确设置了 API 权限(由于能够列出和删除),但是有些不对劲。我正在使用 Ruby 及其 Net::HTTP 类来发出 HTTP 请求,但我也尝试过使用其他语言,甚至是 Github Javascript SDK ( https://github.com/microsoftgraph/msgraph-sdk-javascript ) 和 Java SDK ( https://github.com/microsoftgraph/msgraph-sdk-java )。我所做的每次尝试都会导致相同的 400(无效请求)错误。我的请求如下所示:
PUT /v1.0/drives/b!0jlSfAMWs0mywYCiVQrxB8cBs6dbx0FDr8CYTNg4ITob3Q2lz0OER6Snzs1G_vHh/items/01L5VYWTF6Y2GOVW7725BZO354PWSELRRZ:/test.txt:/content HTTP/1.1
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: application/json
User-Agent: Ruby
Host: graph.microsoft.com
Authorization: Bearer <my auth code>
Content-Type: text/plain
Connection: close
Content-Length: 24
My test.txt file content
返回的错误响应没有用于诊断我的问题的有用信息:
HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: application/json
request-id: c42545c0-ee40-40f3-9c7d-19d0e69d8ac8
client-request-id: c42545c0-ee40-40f3-9c7d-19d0e69d8ac8
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Central US","Slice":"SliceC","Ring":"3","ScaleUnit":"003","RoleInstance":"AGSFE_IN_45"}}
Strict-Transport-Security: max-age=31536000
Date: Mon, 03 Aug 2020 16:23:47 GMT
Connection: close
Content-Length: 215
{
"error": {
"code": "invalidRequest",
"message": "Invalid request",
"innerError": {
"date": "2020-08-03T20:35:44",
"request-id": "c42545c0-ee40-40f3-9c7d-19d0e69d8ac8"
}
}
我已经为此 PUT 请求尝试了几种不同的路径来上传文件并得到相同的错误响应:
sites/#{site_id}/drive/items/01L5VYWTF6Y2GOVW7725BZO354PWSELRRZ:/test.txt:/content
sites/#{site_id}/drive/root:/test.txt:/content
me/drive/items/01FF6DWVN6Y2GOVW7725BZO354PWSELRRZ:/test.txt:/content
me/drive/root:/test.txt:/content
我的应用注册具有以下 API 权限,并且在发出 OAuth 访问令牌请求时我会请求其中的每一个权限:
openid
email
profile
https://graph.microsoft.com/User.Read
https://graph.microsoft.com/Files.Read
https://graph.microsoft.com/Files.Read.All
https://graph.microsoft.com/Files.ReadWrite
https://graph.microsoft.com/Files.ReadWrite.All
https://graph.microsoft.com/Sites.Manage.All
https://graph.microsoft.com/Sites.Read.All
https://graph.microsoft.com/Sites.ReadWrite.All
再次 - 我尝试在任何驱动器中创建文件夹或尝试创建上传会话时遇到类似错误。这些都是 POST 请求,带有一个 JSON 正文到一个稍微不同的 URL,但最终结果是完全相同的....一个 400 错误,绝对没有有用的信息。同样的事情发生在“beta”端点。
除非我是“统一支持或高级客户”,否则 Microsoft 不会帮助我。我尝试立即提交的每个案例都已关闭。
有人有想法么?