Google Drive API v3 更改文件的元数据
我在更改谷歌驱动器上文件的元数据时遇到问题。我得到了从驱动器下载文件的脚本,下载后我想用星号标记文件(星号= True)。
我找到了 v2 API 的解决方案,但它不适用于 v3,我收到错误“资源主体包含不可直接写入的字段”。
我阅读了 v3 的文档,但没有找到如何更改元数据的解决方案。
file = service.files().get(fileId=file_id).execute()
file['starred'] = True
service.files().update(fileId=file_id, body=file).execute()
感谢您的任何帮助。
i got a problem with changing metada of file on google drive. I got script for downloading files from drive and after download i want to mark file with star (starred = True).
I found solution for v2 API, but its not working for v3, where i reciving error "The resource body includes fields which are not directly writable".
I read a documentation for v3 but didnt find solution how to change metadata.
file = service.files().get(fileId=file_id).execute()
file['starred'] = True
service.files().update(fileId=file_id, body=file).execute()
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的问题是您首先执行 file.get 。
这将填充完整的文件资源对象。由于更新方法使用补丁方法,它会尝试更新您发送的每个属性,其中一些属性不可写。您应该只发送您想要更新的字段。
试试这个。
The issue you are having is you are doing a file.get first.
This populates the full file resource object. And since the update method uses patch methodology its trying to update every property that you sent and some of them are not writeable. you should only send the fields you want to update.
Try this.