6

我正在尝试使用从 django-social-auth 获得的 OAuth 令牌来访问用户日历。

所以在我设置的 django-social-auth 配置中:

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

当用户从谷歌回来时,我在数据库中得到一个如下所示的条目:

{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>

我在这里想念什么?

4

2 回答 2

3

这对我有用:

from social_auth.models import UserSocialAuth

def do_something_with_tokens(request):
  tokens = UserSocialAuth.get_social_auth_for_user(request.user).get().tokens
  ...
于 2012-10-06T18:35:57.270 回答
0

哈利路亚!Django-social-auth 返回带有转义正斜杠 (%2F) 的访问令牌。用“/”替换它对我有用。

高温高压

于 2012-01-20T03:11:25.217 回答