0

I am trying to delete google drive folders using the following code block:

from google.oauth2.service_account import Credentials
from googleapiclient.discovery import build
from google.oauth2 import service_account


credentials0 = {
.......
}

credentials = service_account.Credentials.from_service_account_info(credentials0)
drive_service = build('drive', 'v3', credentials=credentials)


folder_to_delete_id = '.......'


drive_service.files().delete(fileId=folder_to_delete_id).execute()

It is showing an error that I don't have enough permission to delete the file. But I have already added the service account as an editor to the given folder. It can do everything but can not delete the folder.

Can anyone help me?

6
  • Try try/except try: drive_service.files().delete(fileId=folder_to_delete_id).execute() print(f"Folder with ID {folder_to_delete_id} has been deleted.") except HttpError as error: print(f"An error occurred: {error}") Commented May 4 at 10:21
  • What scope did you use when you authorized the application? Commented May 4 at 13:51
  • SCOPES = ['googleapis.com/auth/drive'] Commented May 4 at 16:15
  • Anyway, I sorted it out by moving the required folders to another folder. But not deleting. Commented May 4 at 16:16
  • always put full error message because there are other useful information. Commented May 4 at 22:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.