【问题标题】:Error uploading file using MSGraph in onedrive business account在 onedrive 企业帐户中使用 MSGraph 上传文件时出错
【发布时间】:2019-10-10 16:37:26
【问题描述】:

我使用 Microsoft graph 创建了一个将文件上传到 OneDrive 的 Web 应用程序。 文件上传使用上传会话。 https://docs.microsoft.com/ja-jp/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

如果上传目标帐户是企业帐户,则上传文件会失败。 发生的错误是 {" error ": {" innerError ": {" code ":" invalidToken "}," code ":" unauthenticated "," message ":" This access token is not valid on this endpoint. "}}.

但是,如果上传目的地是个人帐户,它会成功 顺便说一句,简单的上传将在商业和个人中成功。 不知道有没有什么措施?

以下是上传过程。
(1)

POST /me/drive/root:/sample.txt:/createUploadSession
Authorization: Bearer {bearer token}
Content-Type: application/json
{
  "item": {
    "@microsoft.graph.conflictBehavior": "rename",
    "name": "sample.txt"
  }
}

(2)响应

HTTP/1.1 200 OK
Content-Type: application/json

{
  "uploadUrl": "https://our-tenant-my.sharepoint.com/personal/our_tenant_onmicrosoft_com/_api/v2.0/drive/items/aaaa/uploadSession?guid='example'&path='example'&overwrite=False&rename=True&dc=0&tempauth=example",
  "expirationDateTime": "2019-05-24T05:07:08.728Z"
}

(3) 将字节上传到上传会话

PUT https://our-tenant-my.sharepoint.com/personal/our_tenant_onmicrosoft_com/_api/v2.0/drive/items/aaaa/uploadSession?guid='example'&path='example'&overwrite=False&rename=True&dc=0&tempauth=example

(4) 返回错误

HTTP/1.1 401
{"error":{"innerError":{"code":"invalidToken"},"code":"unauthenticated","message":"This access token is not valid on this endpoint."}}

顺便说一下,如果是个人账户,响应的uploadUrl是

https://api.onedrive.com/rup/example/more~~~

会回来的。
我可以用这个路径上传。 个人账号和企业账号的UploadUrl不一样,和这个错误有关系吗? 有没有办法解决这个问题?

【问题讨论】:

    标签: office365 microsoft-graph-api onedrive


    【解决方案1】:

    使用 PUT 时不要发送它不被接受的令牌。

    在发出 PUT 调用时包含 Authorization 标头可能会导致 HTTP 401 Unauthorized 响应。

    授权标头和不记名令牌仅应在第一步发出 POST 时发送。发出 PUT 时不应包含它。

    【讨论】:

    • 当我使用 PUT 时,我没有发送令牌。并且错误是未经身份验证而不是未经授权。
    【解决方案2】:

    这个问题已经解决了。 原因是 Web 应用程序的 HTTP 客户端重新排列了 URL 的查询参数。 我用的是Ruby on Rails的法拉第,所以我改变了这个。

    【讨论】:

      猜你喜欢
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-13
      • 1970-01-01
      • 2013-02-23
      • 2016-01-15
      • 1970-01-01
      相关资源
      最近更新 更多