By continuing to navigate on this website, you accept the use of cookies to serve you more relevant services & content.
For more information and to change the setting of cookies on your computer, please read our Cookie Policy.

Google plus API integration with django

Using GPlus integration by Django, we can get the user verified email id, general information, friends in a less span of time, and user can also share articles.

These Following steps are needed for GPlus integration:

    1. creating google app
    2. Authenticating user and getting access token.
    3. Get user information using access token.
    4. Get user friends list.

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.

    Posted On
  • 01 October 2014
  • By
  • Micropyramid

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Introduction to API development using Django REST framework with Example

Introduction to API development with Django REST framework. You can build the API for any Django application. Pre-requisites are Django and OOPS(object oriented programming concepts) ...

Continue Reading...
Custom Decorators To Check User Roles And Permissions In Django

A decorator is a function that takes another function and returns a newer,prettier version of that function.

To know more about decorators in python see ...

Continue Reading...
How to filter a Django Queryset using Extra

Using SQL Queries in Django ORM - Filtering extra objects within in a single query, to reduce the number of queries.

Continue Reading...
open source packages

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties