首页 > 解决方案 > 无法使用 Drive API 从共享的 Google-Drive 空间中删除文件夹,即使我是该文件夹的所有者

问题描述

我正在尝试创建一个 python 脚本,该脚本将使用以下代码删除/垃圾/删除位于谷歌共享驱动器上的文件夹的内容:

    Drive = build('drive', 'v3', credentials=creds)
    def deleteWorkspace():
        principles = Drive.files().list(q="'%s' in parents and not trashed"%(ROOT_FOLDER_ID)).execute().get('files')
        if len(principles)>0:
            for p in principles:
                print(p['name'])
                Drive.files().delete(fileId = p['id'],supportsAllDrives=True)

该脚本运行完成而没有任何错误,但有问题的文件夹及其内容仍然存在于共享驱动器空间中。

我觉得这特别奇怪,因为我是相关文件夹的所有者,并且所有与我类似的问题似乎都已通过使用所有者的凭据得到解决。

https://developers.google.com/drive/api/v3/reference/files/delete?hl=en#response

使用上面的链接以及相应的fileId字符串时p['id'],文件夹及其内容已成功从共享驱动器空间中删除。

关于为什么我的脚本没有达到使用上述链接时所描述的相同结果的任何建议/建议将不胜感激。

标签: python-3.xoauth-2.0google-apigoogle-drive-apigoogle-api-python-client

解决方案


您可能想尝试在命令末尾添加 execute() 以便它运行。

Drive.files().delete(fileId = p['id'],supportsAllDrives=True).execute()

推荐阅读