我的应用程序有drive.file、drive.readonly和drive.metadata.readonly作用域。使用https://github.com/googleapis/google-api-php-client v2.2.2
当认证为Google Drive用户时,它可以很好地获取文件,但只有当这些文件归其他用户(或同一用户)所有时才能正常工作。
存储在共享驱动器(G Suite Business功能)上并与用户共享的文件会导致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."
}
我已经验证了有问题的文件确实可以由该用户通过Drive/Docs等读取。
我已经进入API控制台,并检查了Drive UI集成下的“共享驱动器支持”-这没有什么不同。它也无助于增加更广泛的“驱动器”范围。
发布于 2019-12-19 20:40:11
经过测试,我发现了同样的问题。
当我尝试使用以下HTTP请求从共享驱动器获取文件时
GET /drive/v3/files/<ID-file> HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>
我得到了和你一样的错误:
{
"error": {
"code": 404,
"message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.",
"errors": [
{
"locationType": "parameter",
"domain": "global",
"message": "File not found: 1DIM-vS4058e0X5eutNmOqSr3z0rA1Nqh.",
"reason": "notFound",
"location": "fileId"
}
]
}
}
但在阅读the documentation 时,很明显您需要将supportsAllDrives
参数包含到HTTP请求中。
所以现在添加supportsAllDrives=true
我的请求如下:
GET /drive/v3/files/<File ID>?supportsAllDrives=true HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer <access Token>>
然后我要检索响应中的文件:
{
"mimeType": "image/jpeg",
"kind": "drive#file",
"name": "file.jpg",
"driveId": "<Drive Id>",
"teamDriveId": "<Team Drive ID>",
"id": "<File ID>"
}
https://stackoverflow.com/questions/59404920
复制相似问题