【问题标题】:How to post to Google+?如何发布到 Google+?
【发布时间】:2016-07-22 12:08:47
【问题描述】:

我想制作一些应用程序(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+ 收藏的权利?

//编辑 我是否正确理解document?我需要有付费帐户“Google for Work”来解决我的问题吗?

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

【问题讨论】:

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


    【解决方案1】:

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

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

    因此,如果没有工作帐户,您将无法自动在 Google+ 上发帖。当你有一个时,你可以使用moments.insert(以编程方式插入),或者使用embeddable share button

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 对不起,这不是正确的答案:]我已经更新了问题。
      • 不,您不需要支付谷歌帐户来工作。只需简单地添加这些范围并授权,然后您将获得令牌,使用令牌获取 user_id,然后将活动添加到用户 google+ 帐户。它对我有用。我已经将它集成到我的项目中
      • 我做的每一件事都是按照link做的。在向您的服务帐户委派域范围的权限部分中,我必须转到 URL link 并设置一些东西。尝试去那里给我屏幕“您需要一个 Google for Work 帐户才能登录 my_app.appspot.com。了解更多”。所以我需要“Google for Work”?
      猜你喜欢
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多