Google云端硬盘API-GSuite共享驱动器中存储的文件(仅)出现404错误

时间:2019-12-19 07:18:39

标签: google-drive-api

我的应用程序具有作用域drive.file,drive.readonly和drive.metadata.readonly。 使用https://github.com/googleapis/google-api-php-client v2.2.2

通过Google云端硬盘用户身份验证时,它可以很好地提取文件,但前提是这些文件由另一个用户(或同一用户)拥有。

存储在共享驱动器(G Suite商业功能)上并与用户共享的文件会导致404错误:

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

我已验证该文件确实可以由用户通过云端硬盘/文档等读取。

我进入了API控制台,并检查了Drive UI集成下的“ Shared Drives support”(共享驱动器支持)-这没什么区别。 添加更大的“驱动器”范围也无济于事。

1 个答案:

答案 0 :(得分:1)

经过测试,我发现了同样的问题。

当我尝试通过以下HTTP请求从共享驱动器中获取文件时

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

我遇到了与您相同的错误:

GET /drive/v3/files/<ID-file> HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>

但是在阅读the documentation 时,很明显您需要在HTTP请求中包含{ "error": { "code": 404, "message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.", "errors": [ { "locationType": "parameter", "domain": "global", "message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.", "reason": "notFound", "location": "fileId" } ] } } 参数。

所以现在添加supportsAllDrives我的请求如下:

supportsAllDrives=true

然后我要在响应中检索文件:

GET /drive/v3/files/<File ID>?supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>>