[Python] How to delete google drive folders using Python?

Discussão em 'Python' iniciado por Stack, Maio 4, 2025.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página