在Twython中获取访问令牌错误401

我正试图通过Twython提供用户的Twitter帐户

def twitter_view(request):
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens(callback_url='http://127.0.0.1:8000/confirm/', force_login=True)

request.session['oauth_token'] = auth['oauth_token']
request.session['oauth_token_secret'] = auth['oauth_token_secret']
return HttpResponseRedirect(auth['auth_url'])


def redirect_view(request):
oauth_verifier = request.GET['oauth_verifier']
twitter = Twython(APP_KEY, APP_SECRET)
final_step = twitter.get_authorized_tokens(oauth_verifier)
request.user.twitter_oauth_token = final_step['oauth_token']
request.user.twitter_oauth_token_secret = final_step['oauth_token_secret']
request.user.save()

return redirect('twitterapp:homepage')

我正进入(状态

Twitter API返回了401(未授权),无效/过期令牌

回溯(最近一次通话最后):

文件“/Users/bharatagarwal/my-venv/lib/python2.7/site-packages/django/core/handlers/base.py”,第149行,在get_response response = self.process_exception_by_middleware(e,request)

文件“/Users/bharatagarwal/my-venv/lib/python2.7/site-packages/django/core/handlers/base.py”,第147行,在get_response response = wrapped_callback(request,* callback_args,** callback_kwargs)

文件“/Users/bharatagarwal/projects/twitterproject/mysite/twitterapp/views.py”,第100行,在redirect_view中
final_step = twitter.get_authorized_tokens(str(oauth_verifier))

文件“/Users/bharatagarwal/my-venv/lib/python2.7/site-packages/twython/api.py”,第379行,在get_authorized_tokens ken'),error_code = response.status_code)

TwythonError:Twitter API返回了401(未授权),无效/过期至肯


在第二个Twython实例化中,您必须包含第一步中获得的OAUTH_TOKEN和OAUTH_SECRET_TOKEN。

twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)    

它正在返回无效令牌,因为您使用的实例不包括您收到的令牌。

链接地址: http://www.djcxy.com/p/55917.html

上一篇: Obtaining access token error 401 in Twython

下一篇: Django 'global name' error