2011-09-21 70 views
5

我试图使用从django-social-auth获取的OAuth令牌访问用户日历。从Google数据API(日历)使用django-social-auth的OAuth访问令牌

所以在Django的社会验证配置我设置:

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

当用户从谷歌回来了,我在数据库中保存其中lookes这样的条目:

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

但是现在,当我尝试做这样的事情:

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() 

我总是得到:

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

我在这里错过了什么?

+1

你使用OAuth或OAuth2用户? –

+0

我有完全相同的问题。使我抓狂。我正在使用OAuth,并尝试使用匿名以及注册密钥。 – Tony

回答

0

哈利路亚! Django-social-auth使用转义正斜杠(%2F)返回访问令牌。用“/”替换为我工作。

HTH

3

这个工作对我来说:

from social_auth.models import UserSocialAuth 

def do_something_with_tokens(request): 
    tokens = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens 
    ... 
+0

在我的情况下令牌只是空的。不知道为什么.... – CIF

相关问题