Skip to content

403 error / Forbidden when accessing https://www.googleapis.com/auth/plus.profiles.read in python #337

Description

@GoogleCodeExporter
I had a working application that pulled all users from a domain and grab the 
user picture from Google Plus. After few months it was giving me a "403 error / 
Forbidden when accessing"

This is the code

import httplib2
import pprint

from apiclient.discovery import build

from oauth2client.client import SignedJwtAssertionCredentials

SERVICE_ACCOUNT_EMAIL = '[email protected]'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/xxxx/privatekey.pem'
USER_EMAIL = '[email protected]'

SCOPES = ['https://www.googleapis.com/auth/plus.profiles.read']

def authenticate():
    print "opening the key"
    f = open(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
    key = f.read()
    f.close()
    print "closing the key"

    credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key, scope=SCOPES, sub=USER_EMAIL)
    http = httplib2.Http()
    http = credentials.authorize(http)

    print "getting the credentials"
    return build('plusDomains', 'v1', http=http)

print "calling the authentication"
service = authenticate()

print "calling people service"
people_service = service.people()

print "getting the user profile"
people_document = people_service.get(userId='[email protected]').execute()

print 'ID: %s' % people_document.get('id')
print 'Display name: %s' % people_document.get('displayName')
print 'Image URL: %s' % people_document.get('image').get('url')
print 'Profile URL: %s' % people_document.get('url')


This is the output:
calling the authentication
opening the key
closing the key
getting the credentials
calling people service
getting the user profile
Traceback (most recent call last):
  File "test.py", line 39, in <module>
    people_document = people_service.get(userId='[email protected]').execute()
  File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/apiclient/http.py", line 723, in execute
    raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 403 when requesting 
https://www.googleapis.com/plusDomains/v1/people/[email protected]?alt=json returned 
"Forbidden">

By the way this is the scopes I have in the Google's CPANEL

https://www.googleapis.com/auth/admin.directory.user.readonly
https://www.googleapis.com/auth/plus.profiles.read


Here is the link to the stackoverflow question: 
http://stackoverflow.com/questions/25857123/403-error-forbidden-when-accessing-h
ttps-www-googleapis-com-auth-plus-profil

Original issue reported on code.google.com by [email protected] on 23 Sep 2014 at 6:10

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions