python-3.x - 无法使用 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']
,文件夹及其内容已成功从共享驱动器空间中删除。
关于为什么我的脚本没有达到使用上述链接时所描述的相同结果的任何建议/建议将不胜感激。
解决方案
您可能想尝试在命令末尾添加 execute() 以便它运行。
Drive.files().delete(fileId = p['id'],supportsAllDrives=True).execute()
推荐阅读
- android - 在 OpenCV Camera Android Fragment 中未调用 onCameraFrame 函数
- ruby-on-rails - NoMethodError:服务的未定义方法“set_password”(调用“Service.connection”建立连接):类
- c++ - geotiff坐标变换错误
- html - 如何并排放置两个被边框包围的元素?
- google-classroom - 课程 API 不返回材料集
- java - 如何在 Android Studio 中单击按钮时创建一个新按钮?
- wordpress - 如何将字体真棒添加到自定义文字新闻片段
- angularjs - AngularJS中打开天气应用程序的输出错误
- python - 我的基于矩阵的反向传播算法有什么问题?
- asp.net-mvc - 如何使用 FTP 或使用代码优先迁移的文件系统发布方法更新远程数据库