简体   繁体   中英

Delete files/folders from google drive using API for Python

I am trying to delete a file from google drive using API for python, but the compiler returns "Insufficient Permission: Request had insufficient authentication scopes."

SCOPES1 = 'https://www.googleapis.com/auth/drive.file'
flow = InstalledAppFlow.from_client_secrets_file('client_secrets.json', SCOPES1)
creds = flow.run_local_server(port=8080)

service = build('drive', 'v3', credentials=creds)
file_id = 'xxxx'
service.files().delete(fileId=file_id).execute()

How can I get over this issue?

In order to delete the file (which as far as I know is created by an application other than the one you are using) you will need the scope https://www.googleapis.com/auth/drive .

After that, you have to make sure that you have the valid scopes and applications defined in the API console for your project. To do so, go to console.developers.google.com, select your project on the top dropdown, go to library and check that the drive application is enabled. Afterwards, go to "OAuth consent screen" and verify that the scope https://www.googleapis.com/auth/drive is added in "Scopes for Google APIs".If it is not, make sure to add it.

After these modifications, and assuming the credentials are valid for this project, your script should be able to run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM