Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the OAuth Access Token from django-social-auth with Google data api (calendar)

I'm trying to use the OAuth Token I get from django-social-auth to access the users calendars.

So in the django-social-auth configuration I set:

GOOGLE_CONSUMER_KEY = 'anonymous'
GOOGLE_CONSUMER_SECRET = 'anonymous'
GOOGLE_OAUTH_EXTRA_SCOPE = ['https://www.google.com/calendar/feeds/']

When the user comes back from google, I get an entry in the database which lookes like this:

{u'access_token': u'oauth_token_secret=vvvv&oauth_token=xxxx'}

But now, when I try do something like this:

import gdata.calendar.client

client = gdata.calendar.client.CalendarClient()
client.auth_token = gdata.gauth.OAuthHmacToken('anonymous', 'anonymous', 'xxxx', 'vvvv', gdata.gauth.ACCESS_TOKEN)

client.GetOwnCalendarsFeed()

I always get:

gdata.client.Unauthorized: Unauthorized - Server responded with: 401
<HEAD>
<TITLE>Token invalid - Invalid AuthSub token.</TITLE>
</HEAD>

What am I missing here?

like image 717
Kai Avatar asked Sep 21 '11 08:09

Kai


1 Answers

This works for me:

from social_auth.models import UserSocialAuth

def do_something_with_tokens(request):
  tokens = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
  ...
like image 127
drojascamaggi Avatar answered Oct 05 '22 01:10

drojascamaggi