【发布时间】:2018-08-12 09:37:56
【问题描述】:
作为 a 文件夹的所有者,我想使用 v3 python files API 来删除另一个用户拥有的文件。这是一个反复出现的话题,但我还没有找到完全解释工作流程的解决方案。
我所做的一般假设是我应该能够删除我拥有的文件夹中的文件。
范围:https://www.googleapis.com/auth/drive
尝试永久删除文件时:
service.files().delete( fileId=file_id ).execute()
结果:
<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I? returned "The user does not have sufficient permissions for this file.">
尝试删除文件时:
service.files().update( fileId=file_id, body={'trashed':True} ).execute()
结果:
ERROR: Error deleting file: <HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I?alt=json returned "The user does not have sufficient permissions for this file.">
如果我尝试更新文件权限以将所有者重新定义为我自己:
perms = { 'emailAddress': '<myemail>@gmail.com', 'type': 'user', 'role': 'owner', 'kind': 'drive#permission' }
service.permissions().create( fileId=file_id, transferOwnership=True, body=perms ).execute()
结果:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1zbEBsHRpqbGkDJ6Gh5eU8OxU4IVEAo0I/permissions?alt=json&transferOwnership=true returned "Bad Request. User message: "Sorry, you do not have permission to share."">
这个主题的变体一直在流传,但我还没有找到可行的解决方案。
【问题讨论】:
-
为什么 Google API 允许您删除不属于您的文件?为什么?
-
一个有效的问题。我的回答是:父文件夹属于我。这并非完全史无前例。我被允许删除 linux 目录中另一个用户的文件,其所有者 uid 与我的相同(而不是 root 用户)。
标签: python-2.7 google-api google-drive-api google-api-python-client