【发布时间】:2014-06-26 15:01:32
【问题描述】:
我正在使用 PyDrive (http://pythonhosted.org/PyDrive/) 来简化对 Google Drive 的 API 访问,但在尝试从 Drive 中删除现有文件时遇到了障碍。从文档或对源代码的简短浏览中,我没有看到明确的方法。有人可以指出我正确的方向。干杯。
【问题讨论】:
标签: python google-drive-api pydrive
我正在使用 PyDrive (http://pythonhosted.org/PyDrive/) 来简化对 Google Drive 的 API 访问,但在尝试从 Drive 中删除现有文件时遇到了障碍。从文档或对源代码的简短浏览中,我没有看到明确的方法。有人可以指出我正确的方向。干杯。
【问题讨论】:
标签: python google-drive-api pydrive
更新:此功能已合并。您现在可以致电fi.Delete() 或fi.Trash()。详情请见the docs。
在 PyDrive 文件夹的 files.py 中添加了 5 行代码,用于删除功能。
您可以从以下位置下载更新的 files.py:
https://github.com/ytakefuji/PyDrive/blob/master/files.py
你必须编译生成files.pyc
$ cat help.py
import py_compile
py_compile.compile("files.py")
$ python help.py
示例:通过 oauth2 删除 Google Drive 上的文件:
https://github.com/ytakefuji/PyDrive/blob/master/oauth2_delete.py
编辑: 有问题的行是(添加到 GoogleDriveFile 类):
def DeleteFile(self,file_id):
try:
self.auth.service.files().delete(fileId=file_id).execute()
except errors.HttpError, error:
print 'An error occurred: %s' % error
可以在here找到此功能的文档。
【讨论】:
Scott Blevins 对其进行了编码,但他的代码从未被合并。看起来 pydrive 有点被遗弃了。太糟糕了,因为它非常有用。
只需从此处下载 zip 文件并将旧的 pydrive 代码替换为其内容: https://github.com/smeggingsmegger/PyDrive/tree/Trash_and_Delete
【讨论】: