Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Created August 7, 2013 22:39
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rchrd2/6179550 to your computer and use it in GitHub Desktop.
Save rchrd2/6179550 to your computer and use it in GitHub Desktop.
How to link django-social-auth with google-api-python-client I am creating a gist, because this took me way to long to figure out. Maybe it can save you some time!
import httplib2
from apiclient.discovery import build
from oauth2client.client import AccessTokenCredentials
def connect_helper(user):
c = user.social_auth.get(provider='google-oauth2')
access_token = c.tokens['access_token']
credentials = AccessTokenCredentials(access_token, 'my-user-agent/1.0')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http,
developerKey='...')
return service
@noahpresler
Copy link

You're a godsend!

@neckaros
Copy link

This will not automatically refresh an offline token right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment