Shravan Kumar
Shravan Kumar

Reputation: 33

people.connections.list not returning profile details and contacts in Python using Google-People API

I've connected with Google's People-API in the google console using oauth2.0 by creating credentials. And while I'm trying to get user's profile details and contact details by using this API in google, I'm not able to get that. Below is the sample code for the authentication and getting data.

import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run_flow

# Set up a Flow object to be used if we need to authenticate. This
# sample uses OAuth 2.0, and we set up the OAuth2WebServerFlow with
# the information it needs to authenticate. Note that it is called
# the Web Server Flow, but it can also handle the flow for
# installed applications.
#
# Go to the Google API Console, open your application's
# credentials page, and copy the client ID and client secret.
# Then paste them into the following code.
FLOW = OAuth2WebServerFlow(
    client_id='xxxxxxxxx-xxxxxxxxxxxxxxxxx',
    client_secret='xxxxxxxxxxxxxxxxxxxx',
    scope='https://www.googleapis.com/auth/contacts.readonly',
    user_agent='myapp/2.0',
    redirect_uri='http://localhost')

# If the Credentials don't exist or are invalid, run through the
# installed application flow. The Storage object will ensure that,
# if successful, the good Credentials will get written back to a
# file.
storage = Storage('info.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
  credentials = run_flow(FLOW, storage)

# Create an httplib2.Http object to handle our HTTP requests and
# authorize it with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)

# Build a service object for interacting with the API. To get an API key for
# your application, visit the Google API Console
# and look at your application's credentials page.
people_service = build(serviceName='people', version='v1', http=http)

connections = people_service.people().connections().list('people/me', pageSize=100, personFields='names,emailAddresses').execute()
profile = people_service.people().get('people/me', pageSize=100, personFields='names,emailAddresses').execute()

After running the above code. I got the following error.

Traceback (most recent call last):
  File "people_api_auth.py", line 43, in <module>
    connections = people_service.people().connections().list('people/me', pageSize=100, personFields='names,emailAddresses').execute()
TypeError: method() takes 1 positional argument but 2 were given

Can anyone explain why I'm getting this error. Any help would be greatly appreciated. Thank you!!!

Upvotes: 0

Views: 1504

Answers (1)

Amos Yuen
Amos Yuen

Reputation: 1459

Take a look at the sample at https://developers.google.com/people/quickstart/python

Looks like they use list(resourceName='people/me' instead of list('people/me'

Upvotes: 1

Related Questions