如何使用Google+域API撰写帖子

时间:2016-09-06 07:22:07

标签: python google-app-engine google-api google-plus

我在google appengine和python上编写了一个与社交网络Google+互动的应用程序,特别是我需要使用Google+域名API在Google+上发帖。 我尝试了以下代码:

class Oauth2Handler(BaseHandler):
def get(self):
    flow = flow_from_clientsecrets(
        'client_secret.json',
        scope='https://www.googleapis.com/auth/plus.login '
              'https://www.googleapis.com/auth/plus.me '
              'https://www.googleapis.com/auth/userinfo.email '
              'https://www.googleapis.com/auth/plus.stream.write'
        redirect_uri='http://localhost:8080/oauth2callback'
    )

    # Step1 del protocollo oauth2
    if not self.request.get('code'):
        auth_uri = flow.step1_get_authorize_url()

    # Step2 del protocollo oauth2
    else:
        auth_code = self.request.get('code')
        credentials = flow.step2_exchange(auth_code)
        http = httplib2.Http(cache=memcache)
        http_auth = credentials.authorize(http=http)

        gplus_service = build('plusDomains', 'v1', http=http_auth)
        gplus_service.activities().insert(
        userId='me',
        body={
            'object': {
            'originalContent': 'Happy Monday! #caseofthemondays'
            },
            'access': {
                'items': [{
                'type': 'domain'
                }],
                'domainRestricted': True
            }
        }).execute(http=http_auth)

此代码生成异常:

HttpError: <HttpError 403 when requesting https://www.googleapis.com/plusDomains/v1/people/me/activities?alt=json returned "Forbidden">

我已在此document中读到我必须在我的Google Apps域控制面板中插入范围plus.me和stream.write,但我没有Google for Work帐户。 我该怎么做才能解决这个问题?

感谢

0 个答案:

没有答案