如何post到Google+?
How to post to Google+?
我想制作一些应用程序 (Google App Engine),它将从其他网站获取一些数据并 post 它们在我 Google 中的一个 "collections" 中]+.
现在我有这个代码:
main.py
# -*- coding: utf-8 -*-
import webapp2
import httplib2
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
class UpdateChannelTask(webapp2.RequestHandler):
def get(self):
self.add_news()
def add_news(self):
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'my_project.json',
(
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.stream.write'
)
)
delegate_credentials = credentials.create_delegated('my_email@gmail.com')
http = httplib2.Http()
http = delegate_credentials.authorize(http)
service = build(
'plusDomains',
'v1', http=http)
service.activities().insert(
userId='me',
preview=True,
body={
'object': {
'originalContent': 'Test, my first post in Google+!'
},
'access': {
'items': [{
'type': 'domain'
}],
'domainRestricted': True
}
}).execute()
app = webapp2.WSGIApplication(
routes=[
(r'/update', UpdateChannelTask),
],
debug=True
)
但这不起作用,我收到错误
HttpError: <HttpError 403 when requesting https://www.googleapis.com/plusDomains/v1/people/me/activities?alt=json&preview=true returned "Forbidden">
我的应用如何获得 post 到我的 Google+ collection 的权利?
//编辑
我对这个 document 的理解正确吗?我需要付费帐户 "Google for Work" 才能解决我的问题?
我所做的一切都是根据 link. In section Delegate domain-wide authority to your service account I have to go to URL https://www.google.com/a/cpanel/my_app.appspot.com 并设置一些东西。尝试去那里给我屏幕 "You need a Google for Work account for my_app.appspot.com to login. Learn more"。所以我需要 "Google for Work"?
您必须添加范围
`https://www.googleapis.com/auth/plus.stream.write
https://www.googleapis.com/auth/plus.me
使用此范围将 post 写入 google+ account.By 授权 google+,您将获得 google+ 中 post 的授权令牌.
是的,您需要有一个工作帐户。不幸的是 Google Plus Pages API 未对 public 开放。您可以发送注册请求 here。
这就是您收到 HTTP 403 Forbidden 错误的原因,这意味着服务器收到了您的请求,但拒绝执行您要求的操作。
因此,如果没有工作帐户,您将无法自动 post 到 Google+。当你有一个时,你可以使用 moments.insert (to be inserted programmatically), or with the embeddable share button.
我想制作一些应用程序 (Google App Engine),它将从其他网站获取一些数据并 post 它们在我 Google 中的一个 "collections" 中]+.
现在我有这个代码: main.py
# -*- coding: utf-8 -*-
import webapp2
import httplib2
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
class UpdateChannelTask(webapp2.RequestHandler):
def get(self):
self.add_news()
def add_news(self):
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'my_project.json',
(
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/plus.stream.write'
)
)
delegate_credentials = credentials.create_delegated('my_email@gmail.com')
http = httplib2.Http()
http = delegate_credentials.authorize(http)
service = build(
'plusDomains',
'v1', http=http)
service.activities().insert(
userId='me',
preview=True,
body={
'object': {
'originalContent': 'Test, my first post in Google+!'
},
'access': {
'items': [{
'type': 'domain'
}],
'domainRestricted': True
}
}).execute()
app = webapp2.WSGIApplication(
routes=[
(r'/update', UpdateChannelTask),
],
debug=True
)
但这不起作用,我收到错误
HttpError: <HttpError 403 when requesting https://www.googleapis.com/plusDomains/v1/people/me/activities?alt=json&preview=true returned "Forbidden">
我的应用如何获得 post 到我的 Google+ collection 的权利?
//编辑 我对这个 document 的理解正确吗?我需要付费帐户 "Google for Work" 才能解决我的问题?
我所做的一切都是根据 link. In section Delegate domain-wide authority to your service account I have to go to URL https://www.google.com/a/cpanel/my_app.appspot.com 并设置一些东西。尝试去那里给我屏幕 "You need a Google for Work account for my_app.appspot.com to login. Learn more"。所以我需要 "Google for Work"?
您必须添加范围 `https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me 使用此范围将 post 写入 google+ account.By 授权 google+,您将获得 google+ 中 post 的授权令牌.
是的,您需要有一个工作帐户。不幸的是 Google Plus Pages API 未对 public 开放。您可以发送注册请求 here。
这就是您收到 HTTP 403 Forbidden 错误的原因,这意味着服务器收到了您的请求,但拒绝执行您要求的操作。
因此,如果没有工作帐户,您将无法自动 post 到 Google+。当你有一个时,你可以使用 moments.insert (to be inserted programmatically), or with the embeddable share button.