【发布时间】:2017-03-06 23:33:52
【问题描述】:
我正在努力在 google appengine 中创建一个简单的应用程序,以自动在我的 blogspot 上发布内容。
我已经创建了服务帐户并尝试使用以下代码来调用博客 api 来发布博客。这个运行失败,权限不足错误消息。
urlfetch.set_default_fetch_deadline(45)
service = build('blogger', 'v3')
class MainHandler(webapp2.RequestHandler):
def post(self):
body = {
"kind": "blogger#post",
"id": "9999999999999999",
"title": "SAmple title",
"content": "SAmple blog contents"
}
scopes = ['https://www.googleapis.com/auth/blogger']
credentials = ServiceAccountCredentials.from_json_keyfile_name('secret-key.json', scopes=scopes)
http_auth = credentials.authorize(Http())
request = service.posts().insert(blogId="9999999999999999",body=body)
response = request.execute(http=http_auth)
self.response.out.write(pprint.pformat(response))
app = webapp2.WSGIApplication([
('/postcontents', MainHandler)
], debug=True)
但是我可以通过以下行访问博客详细信息
self.response.write(blogs.get(blogId='9999999999999999').execute(http=http_auth))
我的服务帐户似乎与我的博主帐户没有关联(尽管我的谷歌应用引擎和博主都使用相同的 gmail 帐户)。我如何做到这一点?
【问题讨论】:
标签: python google-app-engine blogger google-api-python-client service-accounts