Insufficient permission error while deleting files google drive

Viewed 1523

I am trying to delete all the files in my google drive.

request = drive_service.files().list().execute()
for a in request["files"]:
    drive_service.files().delete(fileId=a["id"]).execute()

What I am getting:

returns a insufficient permission error.

What I want:

Delete all the files and remove everything from shared with me and make it look like a fresh new drive.

EDIT:

  • image 1

  • image 2

EDIT 2:

Is it possible to remove those files?

EDIT 3

Since the file are shared with me and I think cannot use delete() function with them because I am not the owner. So how can I remove those files from my drive, any workarounds for error insufficient permission.

1 Answers

insufficient permission

Means that the user you have currently authenticated with has not granted you the permission to do what you are trying to do. or the user them selves doesnt have access to do what you are trying to do.

scope

In order for your application to be able to delete files you need write access to the users drive account. When you authenticated your user you supplied a scope If you are following one of the tutorials then you most likely used something like

https://www.googleapis.com/auth/drive.metadata.readonly

Scopes are used to define what access your application needs and to request of the user in order to run your application. This scope would only give you read access to a users drive account. What you need is full access.

https://www.googleapis.com/auth/drive

Make sure to reauthenticate your application again. It should pop up again and ask you to grant it access. Once you have run your application requesting the proper access this will work.

User doesnt own the file

If the user themselves doesn't own the file they cant delete it.

Related