Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File not found error Google Drive API

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.

like image 882
user2676491 Avatar asked Apr 13 '15 13:04

user2676491


People also ask

How do I fix Google authorization error 403?

"code": 403, "message": "The user does not have sufficient permissions for file {fileId}." To fix this error, instruct the user to contact the file's owner and request edit access. You can also check user access levels in the metadata retrieved by files.

Why files are not opening in Google Drive?

If a file won't open, a few things could be wrong: You don't have permission to view the file. You're signed in to a Google Account that doesn't have access. The correct app isn't installed on your phone.


2 Answers

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:

[email protected] 
like image 188
vinzee Avatar answered Oct 08 '22 21:10

vinzee


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.

like image 35
Alain O'Dea Avatar answered Oct 08 '22 21:10

Alain O'Dea