问题描述:

I'm using PyDrive (http://pythonhosted.org/PyDrive/) to simplify API access to the Google Drive, but have hit a stumbling block when attempting to delete an existing file from Drive. I saw no clear way from the documentation or from a brief skim of the source code. Could somebody point me in the right direction. Cheers.

网友答案:

UPDATE: This functionality has been merged. You can now call fi.Delete() or fi.Trash(). See the docs for more details.


5-line codes are added in files.py in PyDrive folder for delete-function.

You can download the updated files.py from:

https://github.com/ytakefuji/PyDrive/blob/master/files.py

you have to compile to generate files.pyc

$ cat help.py
import py_compile
py_compile.compile("files.py")
$ python help.py

example: deleting a file on Google Drive through oauth2:

https://github.com/ytakefuji/PyDrive/blob/master/oauth2_delete.py

EDIT: The lines in question are (added to GoogleDriveFile class):

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 

Documentation of this functionality can be found here.

网友答案:

Scott Blevins coded it, but his code as never been merged. It looks like pydrive is kind of abandoned. Too bad as it is quite useful.

Simply download the zip file from here and replace the old pydrive code with its content: https://github.com/smeggingsmegger/PyDrive/tree/Trash_and_Delete

相关阅读:
Top