如何使用 google 站点 python API 更新附件内容?
我正在尝试编写一个脚本,该脚本将自动更新通过 Google 协作平台创建和管理的网站上的一些附件。这应该是可能的,因为 Google 在 9 月份发布了 Sites API 和 Python GData API 声称支持网站。但是,我能找到的最接近的方法称为 client.update
,它允许我更新附件的元数据,但不能更新内容。
在 Java API 中,更新附件的方法是创建一个新的 MediaFileSource
,然后调用 entry.setMediaFileSource(source)
,然后调用 entry.updateMedia()
>。但是,我在 Python API 中找不到类似的东西。我是愚蠢的,只是错过了一些东西,还是真的无法使用 python API 更新谷歌网站附件?
I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the Sites API in September and the Python GData API claims to support sites. However, the closest method I can find is called client.update
, which allows me to update the metadata of an attachment, but not the content.
In the Java API updating an attachment is done by creating a new MediaFileSource
and then calling entry.setMediaFileSource(source)
followed by entry.updateMedia()
. However, I can't find anything similar in the Python API. Am I dumb and just missing something, or is it really not possible to update a google sites attachment using the python API?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此处提供了有关如何更新附件的内容和元数据(替换附件的内容和元数据小节)
唯一遗漏的是获取
existing_attachment
,这可以通过以下方式轻松完成:The documentation here provides an example on how to update an attachment's content and metadata (subsection Replacing an attachment's content and metadata)
The only thing left out is to get
existing_attachment
which can be done easily with something like this:site api已更新至v1.1;这可能是新添加的
http://code.google。 com/apis/sites/docs/1.0/developers_guide_python.html#UpdatingContent
sites api has been updated to v1.1; this is probably a new addition
http://code.google.com/apis/sites/docs/1.0/developers_guide_python.html#UpdatingContent
好吧,那里的 API 很奇怪,而且文档也不是很清楚。这是我的想法。第一次上传附件时,您可以通过UploadAttachment方法来完成,但在后续尝试中,您需要调用Update。这是执行此操作的代码:
Ok, the API there is weird, and the documentation is not very clear. Here is what I have figured out. First time you upload an attachment, you do it through UploadAttachment method, but on the follow-up attempts, you need to call Update. Here's the code that does it:
有一个 upload_attachment 方法,应该有效。您可能还想查看
There is an upload_attachment method, that should work. You may also want to check out the sample code for Sites API, it uses that method.