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.
"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.
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.
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.
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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With