如何使用googledrivev3更新文件appProperties

2024-10-01 22:38:01 发布

您现在位置:Python中文网/ 问答频道 /正文

文件已上载且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?在

有一个Google Drive API v3 Migration帖子,可以用来获得一些关于文档中没有涉及的事情的想法。这篇文章的垃圾/更新部分讨论了googledriveapiv3中的update功能。 但是它是用Java而不是Python编写的。它建议使用空文件对象:File newContent = new File();

这次PHP的另一篇文章提到了update方法和这个空文件方法:How to update file in google drive v3 PHP

如果这里有人能通过一些Python代码片段来引导我朝着正确的方向前进,我将不胜感激。在


Tags: 文件方法idmyupdatebodyv3drive
1条回答
网友
1楼 · 发布于 2024-10-01 22:38:01

下面的样品怎么样?为了更新appProperties,可以使用drive.files.update. 详细信息是here。在

示例脚本:

body = {'appProperties': {'my_key': 'updated_my_value'}}
updated_file = drive_service.files().update(
    body=body,
    fileId="### file id ###",
    fields='id, appProperties'
).execute()

如果我误解了你的问题,对不起。在

相关问题 更多 >

    热门问题