如何发布到Google+?

时间:2016-07-22 12:08:47

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

我想制作一些应用程序(谷歌应用程序引擎),它将从其他网站获取一些数据并将其发布到我的一个"集合"在谷歌+。

现在我有这个代码: 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">

我的应用如何才能正确发布到我的Google+收藏中?

//编辑 我理解这个document吗?我需要付费帐户&#34; Google for Work&#34;解决我的问题?

我根据link所做的一切。在将域范围权限委派给您的服务帐户的部分中,我必须转到URL https://www.google.com/a/cpanel/my_app.appspot.com并设置一些内容。尝试去那里给我屏幕&#34;你需要一个Google for Work帐户my_app.appspot.com才能登录。了解更多&#34;。所以我需要&#34; Google for Work&#34;?

2 个答案:

答案 0 :(得分:3)

是的,您需要有一个工作帐户。很遗憾,Google Plus Pages API不向公众开放。您可以发送注册here的请求。

这就是为什么你得到 HTTP 403 Forbidden 错误,这意味着服务器收到了你的请求,但拒绝接受你需要的操作。

因此,如果没有工作帐户,您就无法自动发布到Google+。如果您有一个,可以使用moments.insert(以编程方式插入),或使用embeddable share button

答案 1 :(得分:0)

您必须添加范围 `https://www.googleapis.com/auth/plus.stream.write  https://www.googleapis.com/auth/plus.me 用于将帖子写入谷歌+帐户。通过使用此范围授权谷歌+,您将获得授权令牌以在谷​​歌+中发布。

相关问题