【发布时间】:2012-11-09 22:43:43
【问题描述】:
此代码现在可以工作了。
我在通过调用 API 的 python2.7 将新博客文章插入到谷歌的 Blogger 网站时遇到问题。 我有来自谷歌的所有 oauth2client 模块来处理身份验证。 我有权使用 Blogger V3 api - 这是在谷歌开发者控制台上激活的。 我已经使用相同的 credentials.dat 运行了简单的 api 请求:
这有效(不包括完整代码)
service = build('blogger','v3', http=http)
try:
request = service.blogs().get(blogId="6814573853229626501")
response = request.execute()
print response
google api 发现服务让我相信插入帖子的代码应该是这样的 https://developers.google.com/apis-explorer/#p/blogger/v3/blogger.posts.insert
service = build('blogger','v3', http=http)
try:
body = {
"kind": "blogger#post",
"id": "6814573853229626501",
"title": "posted via python",
"content":"<div>hello world test</div>"
}
request = service.posts().insert(blogId="6814573853229626501",body=body)
response = request.execute()
print response
我确定是我搞砸了 body=body 部分?有什么线索吗?
这是我得到的错误:
Traceback (most recent call last):
File "blogger.py", line 104, in <module>
main()
File "blogger.py", line 93, in main
response = request.execute()
File "/usr/local/lib/python2.7/dist-packages/google_api_python_client-1.0c2-py2.7.egg/apiclient/http.py", line 654, in execute
raise HttpError(resp, content, self.uri)
apiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/blogger/v3/blogs/6814573853229626501/posts?alt=json returned "Invalid Value">
如果您有兴趣,我正在尝试从我当时感兴趣的 eBay 数据生成的 google 融合表中发布图表。
【问题讨论】:
标签: python google-api blogger google-api-python-client