21

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
user2676491
  • 3,701
  • 3
  • 17
  • 13
  • paste the http request/response into your question so we can see what's happening. Ostensibly the message is self explanatory, so I'd suspect the value of the file ID. – pinoyyid Apr 13 '15 at 14:42
  • 404 is resource not found. Most probably it is something with url is not correct. Try to access the file in browser if you are able to get the file or not. You can also try this in the API explorer : https://developers.google.com/drive/v2/reference/files/get#try-it – KRR Apr 13 '15 at 19:17

7 Answers7

9

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

Sanjay Nishad
  • 1,537
  • 14
  • 26
8

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.

user2676491
  • 3,701
  • 3
  • 17
  • 13
6

In my case, I simply had not given access to the folder to my service account. Simply sharing it via the web interface solved the problem.

What email address to use:

Check the email address of your service account here:

https://console.cloud.google.com/iam-admin/serviceaccounts?project=NAME_OF_PROJECT&supportedpurview=project

The email address will look like this:

name-of-service-account@name-of-project.iam.gserviceaccount.com 
vvvvv
  • 25,404
  • 19
  • 49
  • 81
6

If you are getting a response like this:

<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'}]">

And the fileId points to a file on a Shared Drive, you'll need to include supportsSharedDrives=true in your request parameters.

Google provides more detail on this in their Implement shared drive support article.

Here's a small example with Python for creating a copy:

googledrive = build('drive', 'v3', credentials=creds)

copy_response = googledrive.files().copy(
    fileId=TEMPLATE_SPREADSHEET_ID,
    body={
        "parents": [
            report_folder_id,
        ],
        'title': report_title
    },
    supportsAllDrives=True
).execute()

In order to run that, you'll want to mix it into the example code from the Python Quickstart for Google Drive API.

Alain O'Dea
  • 21,033
  • 1
  • 58
  • 84
4

I would check to see if the file you are trying to retrieve the metadata for is part of a team drive; if it is then you have to set supportsTeamDrives=True in the request.

ramo21
  • 41
  • 2
1

I got to this question because I was getting a "File not found" error when using the update method.

I was using this line in Python to execute the method:

files_res.update(fileId=f_id, body={"name": f_name}).execute()

I could list the shared file and its parent fine, but update failed, no matter what the scope with this error:

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

I added the supportsAllDrives=True param to the method and it worked:

files_res.update(fileId=f_id, body={"name": f_name}, supportsAllDrives=True).execute()
Zach Young
  • 10,137
  • 4
  • 32
  • 53
0

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.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Roddy P. Carbonell
  • 858
  • 1
  • 11
  • 16