File not found error Google Drive API

2019-02-26 12:31发布

I am using the Drive REST API to download a file. I am making a GET request using the file id and I get a 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"
 }
} 

I have also generated the apikey and I am using it in my GET request.The file does exist so I am unsure what I am missing here.

3条回答
ら.Afraid
2楼-- · 2019-02-26 12:37

This is resolved. I wasn't providing the correct access_token when making the GET request for file metadata. I regenerated the authorization code, access_token and my code is working now.

查看更多
来,给爷笑一个
3楼-- · 2019-02-26 12:37

Make sure scopes are corrects

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 declares the following scopes. Select which ones you want to grant to APIs Explorer.

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

查看更多
劫难
4楼-- · 2019-02-26 12:43

In my case, I was using the file client_secret.json that I had created with the gmail address I use all the time, but I was creating the credentials with another e-mail.

查看更多
登录 后发表回答