此代码现在起作用。
我遇到了一个问题,在通过python2.7致电API插入Google博客网站上的新博客文章。我从Google拥有所有的OAuth2Client模块来处理身份验证。我有权使用Blogger V3 API-这是在Google开发人员控制台上激活的。我运行了使用相同凭据的简单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
我敢肯定是身体=身体部位?有线索吗?
这是我遇到的错误:
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融合表中的发布图表。
您可以以某种方式在任何博客作者上发布
__author__ = 'spandey2405@gmail.com (Saurabh Pandey)'
import sys
from oauth2client import client
from googleapiclient import sample_tools
# Authenticate and construct service.
service, flags = sample_tools.init(
argv, 'blogger', 'v3', __doc__, __file__,
scope='https://www.googleapis.com/auth/blogger')
try:
users = service.users()
# Retrieve this user's profile information
thisuser = users.get(userId='self').execute()
print('This user's display name is: %s' % thisuser['displayName'])
blogs = service.blogs()
# Retrieve the list of Blogs this user has write privileges on
thisusersblogs = blogs.listByUser(userId='self').execute()
for blog in thisusersblogs['items']:
print('The blog named '%s' is at: %s' % (blog['name'], blog['url']))
posts = service.posts()
body = {
"kind": "blogger#post",
"id": "6701167141462934671",
"title": "posted via python",
"content":"<div>hello world test</div>"
}
insert = posts.insert(blogId='6701167141462934671', body=body)
posts_doc = insert.execute()
print posts_doc
except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run'
'the application to re-authorize')
您不需要" data":围绕数据的对象包装器,客户库库将添加服务器,如果服务器需要它。本文档显示了要在插入调用中使用的对象的形式:
https://google-api-client-libraries.appspot.com/documentation/blogger/v3/python/latest/latest/blogger_v3.posts.html#insert