文件已上传且已知file_id
:
media_body = MediaFileUpload(filepath, mimetype=mimetype)
body = {'name': os.path.basename(filepath), 'appProperties':{'my_key': 'my_value'}}
file = drive_service.files().create(body=body, media_body=media_body, fields='id, appProperties').execute()
file_id = file['id']
如何使用 v3 修改文件的appProperties
?
有一个谷歌驱动器API v3迁移帖子,可以用来了解文档中未涵盖的内容。这篇文章的垃圾箱/更新部分讨论了 Google Drive API v3 中的update
功能。 但它是用Java而不是Python编写的。它建议使用空的文件对象:File newContent = new File();
这次PHP的另一篇文章也提到了update
方法和这种空的文件方法:如何在谷歌驱动器v3 PHP中更新文件
如果这里有人能通过几个 Python 片段来指导我朝着正确的方向前进,我将不胜感激。
下面的例子怎么样?为了更新appProperties
,您可以使用drive.files.update。详细信息在这里。
示例脚本:
body = {'appProperties': {'my_key': 'updated_my_value'}}
updated_file = drive_service.files().update(
body=body,
fileId="### file id ###",
fields='id, appProperties'
).execute()
如果我误解了你的问题,我很抱歉。