1
votes

I have used this guide: Quick start for Python.

I also have created an G-Suite account to access to Google Apps domain control panel.

Here my code to insert a post:

__author__ = '[email protected] (Joanna Smith)'

import httplib2
import pprint

from apiclient.discovery import build

from oauth2client.service_account import ServiceAccountCredentials



SERVICE_ACCOUNT_EMAIL = '[email protected]'



SERVICE_ACCOUNT_PKCS12_FILE_PATH = './ProjectTest-9179fae1c392.json'


USER_EMAIL = '[email protected]'


SCOPES = ['https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/plus.stream.write']


def authenticate():

  print 'Authenticate the domain for %s' % USER_EMAIL


  credentials = ServiceAccountCredentials.from_json_keyfile_name(
    SERVICE_ACCOUNT_PKCS12_FILE_PATH, scopes=SCOPES)

  delegate_credentials = credentials.create_delegated(USER_EMAIL)

  http = httplib2.Http()
  http = delegate_credentials.authorize(http)      
  return build('plusDomains', 'v1', http=http)
def activitiesInsert(service):

  user_id = 'me'


  print('Insert activity')
  result = service.activities().insert(
      userId = user_id,
      body = {
          'object' : {
              'originalContent' : 'Happy Monday! #caseofthemondays'
          }
          'access' : {
              'items' : [{
                  'type' : 'domain'
              }],
              'domainRestricted': True
          }
      }).execute()
  print('result = %s' % pprint.pformat(result))


if __name__ == '__main__':
  service = authenticate()
  activitiesInsert(service)

To retrieve ClientID I have to check "Enable delegation on the whole domain G Suite" on Service account keys, and I also have added scopes to client ID from Google Apps domain control panel.

But when I run my code it output this error:

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

Why?

Do i need subscribe in this form? https://developers.google.com/+/web/api/rest/pages-signup

EDIT: i done screenshot for Authorizations, it seems that ok to me.

enter image description here

enter image description here

enter image description here

enter image description here

1
UPDATE: i did it, i did configure Google+ for the first access. - ITS ITS

1 Answers

0
votes

403 forbidden means that you do not have permissions to do what ever it is you are trying to do. In this case insert into the domains activities page. The first thing you need to do is double check the service account was added to the domain account and it has permissions needed. This might help Perform Google Apps domain-wide delegation of authority

Remember this is the Google+ domains API you are using. This will post to the domains account activity page. This is not going to post anything to the Google+ social media website.

The Google Plus pages API is for writing to pages on the Google+ social media website. It is in private beta.