1. Creating Google App
a. To create an app, click on click on create a project on top of a page. Here you can give application name, then the project will be created.
b. In order to create client id, secret, we must enter our Application Details(app name, home page URL, logo URL, privacy url, terms and service URL), Application Type Redirected URLs.
c. Now to get client id, secret click on menu icon on left side of the page, then select API Manager --> Credentials.
d. Click on New credentials to create OAuth client ID to access users data. Here We can also create other keys like API key for using google maps.
2. Authenticating user and getting access token
a. Here We have to create a GET request for asking user permission.
GET https://accounts.google.com/o/oauth2/auth?client_id=CLIENT_ID&response_type=code&scope=SCOPE&redirect_uri=REDIRECT_URI&state=1235dfghjkf123
CLIENT_ID: your app client id,
SCOPE: List of permissions to request from the person using your app
For ex:
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email
https://www.google.com/m8/feeds/contacts/
REDIRECT_URI: The url which you want to redirect after user login and this url must be set in the app registered redireted urls.
b. If user accepts the permissions, then authorization code to redirected url.
c. Then we get accesstoken with the post request.
POST https://accounts.google.com/o/oauth2/token?grant_type='authorization_code'&redirect_uri={redirect_uri}&&client_id={client_id}&client_secret={client_secret}&code={authorization_code}
3. Get user information using access token
GET https://www.googleapis.com/oauth2/v1/userinfo&access_token={access_token}
Json Response will contain user general information.
4. Get user friends list
To get User Friends, You need to enable google contacts api manager --> overview --> Google Api's
We can get contact api auth token using get request.
auth_token = gdata.gauth.OAuth2Token(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=SCOPE,
user_agent='dummy-sample'
)
Here SCOPES can be:
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email
https://www.google.com/m8/feeds/contacts/.
auth_token.access_token = accesstoken
gdata_client = gdata.contacts.client.ContactsClient(source='')
gdata_client = auth_token.authorize(gdata_client)
qry = gdata.contacts.client.ContactsQuery(max_results=3000)
feed = gdata_client.get_contacts(query=qry)
Here We can get user friends list with their general basic information.