Google plus API integration with django

Reading Time : ~ .

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.

    By Posted On
SENIOR DEVELOPER at MICROPYRAMID

Need any Help in your Project?Let's Talk

Latest Comments
Related Articles
Celery Flower to monitor task queue Swetha Naretla

Celery is a task queue that is to built an asynchronous message passing system. It can be used as a bucket where programming tasks can ...

Continue Reading...
Generate PDF from HTML in django using weasyprint Swetha Naretla

WeasyPrint is to combine multiple pieces of information into an HTML template and then converting it to a PDF document.

Continue Reading...
Factory Boy - An alternative for Fixtures Shirisha Gaddi

Factory Boy is a fixtures replacement tool. It allows you to use objects customized for the current test, while only declaring the test-specific fields. For ...

Continue Reading...

Subscribe To our news letter

Subscribe to our news letter to receive latest blog posts into your inbox. Please fill your email address in the below form.
*We don't provide your email contact details to any third parties