找不到文件错误Google Drive API

时间:2015-04-13 13:40:18

标签: google-drive-api

我正在使用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"
 }
} 

我还生成了apikey,我在我的GET请求中使用它。文件确实存在,所以我不确定我在这里缺少什么。

3 个答案:

答案 0 :(得分:5)

这已经解决了。在发出文件元数据的GET请求时,我没有提供正确的access_token。我重新生成了授权码access_token,我的代码现在正在运行。

答案 1 :(得分:2)

确保范围更正

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'
  ]
});

Drive API声明了以下范围。选择要授予API Explorer的那些。

Sorce:https://developers.google.com/apis-explorer/#p/drive/v3/drive.files.get

答案 2 :(得分:0)

在我的情况下,我使用的是我用我一直使用的gmail地址创建的文件client_secret.json,但是我用另一封电子邮件创建了凭据。