Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)
edited by

In the chase to list all (to incorporate Other) Contacts for a Gmail/GSuite client. The current People API doesn't uphold this usefulness, noticing the accompanying strings: 

Discovered this string here, affirming such change in the API: Google Contacts API versus People API 

When jumping further, it appears to be the Contacts API is as yet working and can be utilized by means of gdata

Be that as it may, in view of the accompanying repo, there's restricted documentation on execution utilizing OAuth2 (userID, token, refreshToken), which is the current hindrance to getting the rundown of Other Contacts 

Any assistance would be significantly refreshing, much appreciated!

1 Answer

0 votes
by (26.4k points)

Try following code:

import gdata

import gdata.gauth

import gdata.contacts.client

import json

import requests

GOOGLE_CLIENT_ID = 'GOOGLE_CLIENT_ID'  # Provided in the APIs console

GOOGLE_CLIENT_SECRET = 'GOOGLE_CLIENT_SECRET'  # Provided in the APIs console

ACCESS_TOKEN = 'ACCESS_TOKEN' # given from a prior OAuth2 workflow, along with userID and refreshToken

REFRESH_TOKEN = 'REFRESH_TOKEN'

# GData with access token

token = gdata.gauth.OAuth2Token(

    client_id=GOOGLE_CLIENT_ID,

    client_secret=GOOGLE_CLIENT_SECRET,

    scope='https://www.google.com/m8/feeds',

    user_agent='app.testing',

    access_token=ACCESS_TOKEN,

    refresh_token=REFRESH_TOKEN)

contact_client = gdata.contacts.client.ContactsClient()

token.authorize(contact_client)

feed = contact_client.GetContacts()

for entry in feed.entry:

  entry.title.text

  for e in entry.email:

    e.address

# JSON with access token

r = requests.get('https://www.google.com/m8/feeds/contacts/default/full?access_token=%s&alt=json&max-results=50&start-index=0' % (access_token))

data = json.loads(r.text)

print data

Interested to know more details about python? Come and Join python certification course.

Browse Categories

...