插入使用Python失败的post Blogger API

插入使用Python失败的post Blogger API,python,google-api,blogger,google-api-python-client,Python,Google Api,Blogger,Google Api Python Client,这段代码现在可以工作了 我在通过python2.7调用API将一篇新的博客文章插入到谷歌的博客网站时遇到了一个问题。 我拥有google提供的所有oauth2client模块来处理身份验证。 我有使用Blogger V3 api的权限-这是在google开发者控制台上激活的。 我已使用相同的credentials.dat运行了简单的api请求,这些请求已起作用: 这已成功(不包括完整代码) GoogleAPI发现服务让我相信,插入帖子的代码应该是这样的 service=build('blogg

这段代码现在可以工作了

我在通过python2.7调用API将一篇新的博客文章插入到谷歌的博客网站时遇到了一个问题。 我拥有google提供的所有oauth2client模块来处理身份验证。 我有使用Blogger V3 api的权限-这是在google开发者控制台上激活的。 我已使用相同的credentials.dat运行了简单的api请求,这些请求已起作用:

这已成功(不包括完整代码)

GoogleAPI发现服务让我相信,插入帖子的代码应该是这样的

service=build('blogger','v3',http=http)
尝试:
正文={
“种类”:“博主帖子”,
“id”:“68145738532296201”,
“标题”:“通过python发布”,
“内容”:“你好,世界测试”
}
request=service.posts().insert(blogId=“68145738532296201”,body=body)
response=request.execute()
打印响应
我肯定是我弄糟的身体部位?有什么线索吗

以下是我得到的错误:

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">
回溯(最近一次呼叫最后一次):
文件“blogger.py”,第104行,在
main()
文件“blogger.py”,第93行,主
response=request.execute()
文件“/usr/local/lib/python2.7/dist packages/google_api_python_client-1.0c2-py2.7.egg/apiclient/http.py”,第654行,在execute中
引发HttpError(resp、content、self.uri)
apiclient.errors.HttpError:
如果您感兴趣,我正在试验从我的google fusion表中发布图表,这些图表是由我当时感兴趣的易趣数据生成的。

您不需要“数据”:数据周围的对象包装,如果服务器需要,客户端库将添加这些内容。此文档显示要在insert调用中使用的对象的形式:


你可以在任何博客上发表文章

__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')
\uuuu作者spandey2405@gmail.com(索拉布·潘迪)
导入系统
从oauth2client导入客户端
从GoogleAppClient导入示例工具
#验证和构造服务。
服务,标志=sample_tools.init(
argv,'blogger','v3','uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu,
范围=https://www.googleapis.com/auth/blogger')
尝试:
users=service.users()
#检索此用户的配置文件信息
thisuser=users.get(userId='self').execute()
打印('此用户的显示名称为:%s'%thisuser['displayName'])
blogs=service.blogs()
#检索此用户具有写入权限的博客列表
thisusersblogs=blogs.listByUser(userId='self').execute()
对于thisusersblogs['items']中的博客:
打印('名为\'%s\'的日志位于:%s'(日志['name'],日志['url']))
posts=service.posts()
正文={
“种类”:“博主帖子”,
“id”:“6701167141462934671”,
“标题”:“通过python发布”,
“内容”:“你好,世界测试”
}
insert=posts.insert(blogId='6701167141462934671',body=body)
posts\u doc=insert.execute()
打印文件
除client.AccessTokenRefreshError外:
打印('凭据已被吊销或过期,请重新运行'
'重新授权的应用程序')

太棒了!工作得很好。编辑了上述代码以显示正确的解决方案。您能否共享包括身份验证代码在内的整个代码?我也有这个问题。提前谢谢
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">
__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')