Reputation: 9
As the owner of the a folder I want to use the v3 python files API to remove a file that is owned by another user. This is a recurrent topic, but I have not found a solution that fully explains the workflow.
The general assumption I am making is that I should be able to remove files in a folder that I own.
Scope: https://www.googleapis.com/auth/drive
When trying to permanently delete a file:
service.files().delete( fileId=file_id ).execute()
Results in:
<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I? returned "The user does not have sufficient permissions for this file.">
When trying to trash the file:
service.files().update( fileId=file_id, body={'trashed':True} ).execute()
Results in:
ERROR: Error deleting file: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I?alt=json returned "The user does not have sufficient permissions for this file.">
If I try to update the file permission to redefine the owner as myself:
perms = { 'emailAddress': '<myemail>@gmail.com', 'type': 'user', 'role': 'owner', 'kind': 'drive#permission' }
service.permissions().create( fileId=file_id, transferOwnership=True, body=perms ).execute()
Results in:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I/permissions?alt=json&transferOwnership=true returned "Bad Request. User message: "Sorry, you do not have permission to share."">
Variations of this topic have been floating around, but I haven't found a solution that works.
Upvotes: 0
Views: 1176
Reputation: 117271
"The user does not have sufficient permissions for this file."
Means exactly that you do not have the permissions needed to preform the action you are trying to preform. You can not delete a file that you do not own. Even if the file is in a directory that you do own. This is a limitation in Google drive and has nothing to do with your code.
The solution is to get the owner of the file to delete it or to give you ownership of the file in question.
Upvotes: 1