我正在使用Drive REST API下载文件.我正在使用文件ID发出GET请求,我得到了一个file not found exception.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found: xxxxx",
"locationType": "other",
"location": "file"
}
],
"code": 404,
"message": "File not found: xxxxx"
}
}
Run Code Online (Sandbox Code Playgroud)
我也生成了apikey,我在我的GET请求中使用它.文件确实存在,所以我不确定我在这里缺少什么.
就我而言,我只是没有向我的服务帐户授予对该文件夹的访问权限。只需通过网络界面共享即可解决问题。
在此处检查您的服务帐户的电子邮件地址:
电子邮件地址将如下所示:
name-of-service-account@name-of-project.iam.gserviceaccount.com
Run Code Online (Sandbox Code Playgroud)
如果您收到如下回复:
<HttpError 404 when requesting https://www.googleapis.com/drive/v3/files/REDACTED_FILE_ID/copy?alt=json returned "File not found: REDACTED_FILE_ID.". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'File not found: REDACTED_FILE_ID.', 'locationType': 'parameter', 'location': 'fileId'}]">
Run Code Online (Sandbox Code Playgroud)
并且 fileId 指向共享驱动器上的文件,您需要在请求参数中包含supportsSharedDrives=true。
Google 在其实施共享驱动器支持文章中提供了更多详细信息。
下面是一个使用 Python 创建副本的小示例:
<HttpError 404 when requesting https://www.googleapis.com/drive/v3/files/REDACTED_FILE_ID/copy?alt=json returned "File not found: REDACTED_FILE_ID.". Details: "[{'domain': 'global', 'reason': 'notFound', 'message': 'File not found: REDACTED_FILE_ID.', 'locationType': 'parameter', 'location': 'fileId'}]">
Run Code Online (Sandbox Code Playgroud)
为了运行它,您需要将其混合到Google Drive API 的 Python 快速入门 的示例代码中。
小智 5
确保范围是校正
var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: ['https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.metadata'
]
});
Run Code Online (Sandbox Code Playgroud)
Drive API 声明了以下范围。选择您要授予 APIs Explorer 的那些。
来源:https : //developers.google.com/apis-explorer/#p/drive/v3/drive.files.get
小智 5
我会检查您尝试检索元数据的文件是否是团队驱动器的一部分;如果是,那么您必须supportsTeamDrives=True在请求中进行设置。
| 归档时间: |
|
| 查看次数: |
10432 次 |
| 最近记录: |