# Using Google Data APIs with django apps

DevFeed: [Using Google Data APIs with django apps](<https://devfeed.tech/articles/using-google-data-apis-with-django-apps-19990.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2014/06/07/using-google-apis-in-django/>)

Published: 2014-06-07T00:00:00Z

Content type: tutorial

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [Google](<https://devfeed.tech/topics/google.md>), [API](<https://devfeed.tech/topics/api.md>), [Django](<https://devfeed.tech/topics/django.md>), [Authentication](<https://devfeed.tech/topics/authentication.md>), [Python](<https://devfeed.tech/topics/python.md>), [Library](<https://devfeed.tech/topics/library.md>), [pip](<https://devfeed.tech/topics/pip.md>)

Tags: [apis](<https://devfeed.tech/tags/apis.md>), [authentication](<https://devfeed.tech/tags/authentication.md>), [django](<https://devfeed.tech/tags/django.md>), [google](<https://devfeed.tech/tags/google.md>), [library](<https://devfeed.tech/tags/library.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

This tutorial explains how to integrate Google Data APIs into a Django application using the GData Python client library. It covers creating a Google project, enabling APIs, configuring credentials and redirect URIs, authenticating users, storing tokens in the session, and making API calls such as retrieving contacts.

## Source excerpt

####Setting up a Google Project In order to use any of the Google APIs for your application, first you need to set up a project in the Google Developer's Console. Enable all the APIs that you want to use in the APIs tab under APIs and auth. Under the Credentials tab, create a Client ID and Client secret which is used for communication between your application and the API. Enter all the allowed redirect urls in the Redirect URIs field. These are the URLs to which the application redirects after a user is successfully authenticated. You can change these URLs any time you want. Now your Google App is ready for use. We wanted to create a small application where users can invite their google contacts to join HackerEarth. ####Dependencies We use the GData python client library, which makes it easy to interact with these Google services. You can install it using pip: sudo pip install gdata or install it from [source](https://code.google.com/p/gdata-python-client/downloads/list). ####Authentication First we need to define some constants that we will use througout the application #Obtained from Google Project Settings GOOGLE_CLIENT_ID = <Your Client ID> GOOGLE_CLIENT_SECRET = <Your Client Secret> #Variable that specifies the data you want to access GOOGLE_SCOPE = "http(s)://www.google.com/m8/feeds/" #URL where the flow should go on successful authentication GOOGLE_APPLICATION_REDIRECT_URI = <Some URL> GOOGLE_REDIRECT_SESSION_VAR = <some arbitary value> Since we wanted to use the Contacts API we used the above mentioned scope. A list of other scopes is given here. The first step for authentication is generation of an authentication token. Since we have written a separate view to handle the auth token after successful login, we are setting the authentication token in the session so that the same token can be accessed in both the views. #Try to fetch the authentication token from the session auth_token = request.session.get('google_auth_token') #If an authentication token does