【问题标题】:Google Drive Api v3 upload to sharedDrive not working even with supportsAllDrives=true即使使用supportsAllDrives = true,Google Drive Api v3也无法上传到sharedDrive
【发布时间】:2021-09-03 11:56:43
【问题描述】:

我正在尝试将图像上传到共享驱动器中的文件夹。我设法在我的云端硬盘上做到这一点,但是当我试图在共享云端硬盘上实现这一点时,我收到以下错误:

{
  "error": {
    "code": 404, 
    "message": "File not found: 1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8.", 
    "errors": [
      {
        "locationType": "parameter", 
        "domain": "global", 
        "message": "File not found: 1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8.", 
        "reason": "notFound", 
        "location": "fileId"
      }
    ]
  }
}

这让我现在发疯了,因为我已经多次阅读文档但找不到解决方案。我在 Android 上尝试过使用RetrofitPostman 甚至是 Google 提供的 OAuth2 Playground

请求就是这个,从OAuth2 Playground复制粘贴:

POST /upload/drive/v3/files?uploadType=multipart HTTP/1.1
Host: www.googleapis.com
Content-length: 50295
Content-type: multipart/related; boundary="===============323232404548=="
Authorization: Bearer ya29.a0AfH6SMBHmEo0Q9-8dXhhCY7wGrTj9PsFTCd0YUdLtyGJSfdO
--===============323232404548==
Content-type: application/json

{
   "supportsAllDrives": true,
   "driveId":"0APRAdsf3Sdfsk9PVA",
   "name":"test.jpeg",
   "parents":[
      "1ZQuuXVDx3I5rs6OnH8WvbWfo6HplnfW8"
   ]
}
--===============323232404548==
Content-type: image/jpeg

究竟是什么问题?我也尝试在请求的标头中使用driveIdsupportsAllDrives

非常感谢任何帮助。我关注的链接:

https://developers.google.com/drive/api/v3/manage-uploads#multiparthttps://developers.google.com/drive/api/v3/reference/files/create

【问题讨论】:

    标签: android google-drive-api retrofit2 google-drive-android-api google-drive-shared-drive


    【解决方案1】:

    document 中所示,supportsAllDrives 是一个查询参数。这意味着它应该包含在 URI 中,而不是请求正文中。

    发件人:

    https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart
    

    收件人:

    https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&supportsAllDrives=true
    

    如果查询参数中不包含supportsAllDrives,则默认值为false。这会导致您的响应显示“找不到文件”消息,因为它无法找到或访问共享驱动器。

    【讨论】:

    • 是的,它甚至支持TeamDrives=true,
    • supportsTeamDrives 和 supportsAllDrives 有什么区别,我们应该在哪里使用 supportsTeamDrives 或 supportsAllDrives?
    猜你喜欢
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 2021-07-15
    • 2020-07-22
    • 2018-09-29
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多