I use a service account that is content-manager. I have no problem uploading files to the shared drive using the drive-api from python. Using
service.files().list(q="name='file_name'", fields="files(id)").execute()
I obtain the file_id from my code. This file_id is the right one based on the link to the file.
When I perform the following statement:
response = service.files().update(fileId=file_id, body={'trashed': True}).execute()
I get a
404: file not found.
How to resolve this ? With my personal account (also as content-manager) I have no problems trashing the file.
Requirements
If you clearly understand how to impersonate an account you can skip to the
Solution
step.First of all you will need a service account
Delegate domain-wide authority
Make sure that you are correctly calling the API
Solution
By default Python Google Drive API client V3 doesn't include shared drive files, that's why you have to explicitly pass a parameter
supportsAllDrives
and set it to True and before that you should list your files in order to know the fileId parameter by usingincludeItemsFromAllDrives
andsupportsAllDrives
. Here's an example to list all the files in all your drives and how to trash a file in a Shared Drive using a service account:Otherwise if you already know the fileId just use the
update
part.Reference
Python Google Drive API client V3 > Update a file
Google Identity Platform > Impersonate a user by using a service account