【问题标题】:Deleting a File via PyDrive通过 PyDrive 删除文件
【发布时间】:2014-06-26 15:01:32
【问题描述】:

我正在使用 PyDrive (http://pythonhosted.org/PyDrive/) 来简化对 Google Drive 的 API 访问,但在尝试从 Drive 中删除现有文件时遇到了障碍。从文档或对源代码的简短浏览中,我没有看到明确的方法。有人可以指出我正确的方向。干杯。

【问题讨论】:

    标签: python google-drive-api pydrive


    【解决方案1】:

    更新:此功能已合并。您现在可以致电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找到此功能的文档。

    【讨论】:

    • 除了github链接,能否提供这里内联的diff的相关部分,并解释一下?
    • files.py 中添加最后 5 行
    【解决方案2】:

    Scott Blevins 对其进行了编码,但他的代码从未被合并。看起来 pydrive 有点被遗弃了。太糟糕了,因为它非常有用。

    只需从此处下载 zip 文件并将旧的 pydrive 代码替换为其内容: https://github.com/smeggingsmegger/PyDrive/tree/Trash_and_Delete

    【讨论】:

    • 很好的发现。是的,这是一个有用的小图书馆,可惜开发似乎已经停止。感谢您分享您的发现。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    相关资源
    最近更新 更多