簡體   English   中英

使用來自django-social-auth的OAuth訪問令牌與Google數據api(日歷)

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

我正在嘗試使用我從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>

我在這里錯過了什么?

這對我有用:

from social_auth.models import UserSocialAuth

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

哈利路亞! Django-social-auth返回帶有轉義正斜杠(%2F)的訪問令牌。 用“/”替換它對我有用。

HTH

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM