2011-09-21 26 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

相關問題