【问题标题】:Unable to delete a folder from a shared Google-Drive space, using Drive API, even though I am the owner of the folder无法使用 Drive API 从共享的 Google-Drive 空间中删除文件夹,即使我是该文件夹的所有者
【发布时间】:2021-06-24 17:42:02
【问题描述】:

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

    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

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

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

【问题讨论】:

    标签: python-3.x oauth-2.0 google-api google-drive-api google-api-python-client


    【解决方案1】:

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

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

    【讨论】:

    • 哦,哇,真尴尬 xD 非常感谢,工作就像一个魅力!我真的认为这个问题不仅仅是疏忽。
    猜你喜欢
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    相关资源
    最近更新 更多