3

我想制作一些应用程序(Google App Engine),它将从其他网站获取一些数据并将它们发布到我在 Google+ 中的“收藏”之一中。

现在我有这个代码: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+ 收藏集的权利?

//edit 我是否正确理解了这份文件?我需要有付费帐户“Google for Work”来解决我的问题吗?

我所做的一切都是根据链接做的。在将域范围的权限委托给您的服务帐户部分中,我必须转到 URL https://www.google.com/a/cpanel/my_app.appspot.com并设置一些东西。尝试去那里给我屏幕“您需要一个 Google for Work 帐户才能登录 my_app.appspot.com。了解更多”。所以我需要“Google for Work”?

4

2 回答 2

3

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

这就是您收到HTTP 403 Forbidden错误的原因,这意味着服务器收到了您的请求,但拒绝采取您要求的操作。

因此,如果没有工作帐户,您将无法自动发布到 Google+。当你有一个时,你可以使用moment.insert(以编程方式插入),或者使用可嵌入的共享按钮

于 2016-09-29T08:32:16.093 回答
0

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

于 2016-07-22T12:30:30.177 回答