3

I want to make some application (Google App Engine) which will be fetching some data from other websites and post them in one of my "collections" in Google+.

For now I have this code: 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
)

but this does not work, I get error

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

How can my app gain right to post to my Google+ collection?

//edit Am I understand this document correctly? I need to have paid account "Google for Work" to solve my problem?

Everything I do I do according to 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 and setup something. Attempt to go there gives me screen with "You need a Google for Work account for my_app.appspot.com to login. Learn more". So I need "Google for Work"?

vlad.rad
  • 1,055
  • 2
  • 10
  • 28
BPS
  • 1,133
  • 1
  • 17
  • 38

2 Answers2

3

Yes, you need to have a Work Account. Unfortunately the Google Plus Pages API is not open to the public. You can send a request to sign up here.

That's why you get the HTTP 403 Forbidden error, which means that server got your request, but refused to take the action you requiered.

So you can't automatically post to Google+ without a Work account. When you have one, you can either use moments.insert (to be inserted programmatically), or with the embeddable share button.

vlad.rad
  • 1,055
  • 2
  • 10
  • 28
0

You have to add the scope `https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me for writing the post to google+ account.By authorizing google+ using this scope, you are get the authorization token to post in google+ .

Prakash P
  • 342
  • 1
  • 9
  • Sorry It's not right answer :] I've updated question. – BPS Jul 22 '16 at 14:11
  • No you dont need to paid google account for work. Just simply add these scopes and authorize, then you will get the token , fetch the user_id using the token , then add the activity to the user google+ account. Its simply works for me. I have integrated it in my project – Prakash P Jul 25 '16 at 05:03
  • Everything I do I do according to [link](https://developers.google.com/+/domains/quickstart/python). In section **Delegate domain-wide authority to your service account** I have to go to URL [link](https://www.google.com/a/cpanel/my_app.appspot.com) and setup something. Attempt to go there gives me screen with "You need a Google for Work account for my_app.appspot.com to login. Learn more". So I need "Google for Work"? – BPS Sep 14 '16 at 13:31