1
我有一个网络应用程序,允许用户创建和编辑Google云端硬盘文件。我能够创建并保存新文件。但是当我想更新现有文件时,我无法做到这一点。根据Google Drive API的参考,更新现有的文件用户需要为该文件提供'fileId'。但是,如何获得特定文件的fileId?我有我的文件标题,但如何获得'fileId'?如何获取Google Drive文件的'fileId'?
我使用下面的代码来做到这一点:
fileId = <How to get this?>
media_body = MediaFileUpload(filename, mimetype='text/x-script.phyton', resumable=True)
body = {
'title': filename,
'description': 'File saved from Pythonista app',
'mimeType': 'text/x-script.phyton'
}
existing_file = service.files().get().execute()
if existing_file:
resource = service.files().update(
fileId=fileId,
body=existing_file,
newRevision=True,
media_body=media_body).execute()