Integration Of GitHub API with python django

Using Github integration by Django, we can get the user verified email id, general information, git hub URL, id, disk usage, public, private repo's, gists and followers, following in a less span of time.

These Following steps are needed for Github integration:

1. creating git hub app

2. Authenticating user and getting an access token.

3. Get user information, work history using access token.

1. Creating Github App

a. To create an app, click on create an application on top of a page.

Here you can give application name then the application will be created.

b. Now you can get the client id, secret of an application and you can give redirect urls of your applications.

2. Authenticating user and getting an access token.

a. Here We have to create a GET request for asking user permission.

POST  "https://github.com/login/oauth authorize?client_id=GIT_APP_ID&redirect_uri=REDIRECT_URL&scope=user,user:email&state=dia123456789ramya"

GIT_APP_ID: your application client id,

SCOPE: List of permissions to request from the person using your app

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 sent to redirected url.

c. Then we get accesstoken with the post request and the following params.
  params = {     'grant_type': 'authorization_code',     'client_id': {{ Your Application id }},     'redirect_uri': {{ Your Redirect }}     'client_secret': settings.GIT_APP_SECRET,    'code': request.GET.get('code')    }

info = requests.post("https://github.com/login/oauth/access_token", data=params)

from urlparse import parse_qsl

ac = dict(parse_qsl(info.text))

params = {'access_token': ac['access_token']}

3. Get user information using access token with json response

  GET  "https://api.github.com/user"

From the JSON response we can get the general information, git hub URL, id, disk usage, public, private repo's, gists and followers, following.

We can get the user emails from the get request using JSON response

GET  "https://api.github.com/user/emails"

From the json response, You can get the user emails

Posted On 22 January 2016 By MicroPyramid


Need any Help in your Project?Let's Talk

Latest Comments
Is Django best framework for your web application development

Is Django best framework for your web application development

Continue Reading...
How to maintain user session across sub domains in Django

Nowadays, people are using wildcard domains to provide same user experience across different domains. Using subdomains, we can be able to host multiple sites with …

Continue Reading...
What is Django CRM and it’s advantages

Here in this blog you can find about CRM, Importance of CRM in sales, Types of CRM, How django crm helps for business and it’s …

Continue Reading...
Implementation of single sign on using auth0 in django application

As the no of applications increases, users need to create username & passwords, need to remember for each application. Users can't remember these details and, …

Continue Reading...
Customizing Django REST API Serializers

Customizing Django REST API Serializers

Continue Reading...

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