我正在使用 PyDrive ( http://pythonhosted.org/PyDrive/ ) 来简化对 Google 云端硬盘的 API 访问,但在尝试从云端硬盘中删除现有文件时遇到了障碍。我从文档或对源代码的简要浏览中没有看到明确的方法。有人能指出我正确的方向吗?干杯。
最佳答案
更新:此功能已合并。您现在可以调用 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 云端硬盘上的文件:
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 .
关于python - 通过 PyDrive 删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24433934/