我正在使用twython 库,与 twitter python 库进行握手。我正在我的本地服务器上测试东西,127.0.0.1:8000
这是我的第一个 django 视图,它为用户生成 twitter 令牌。
def twitter_auth(request):
"""
The view function that initiates the entire handshake.
For the most part, this is 100% drag and drop.
"""
# Instantiate Twython with the first leg of our trip.
twitter = Twython(
settings.TWITTER_KEY,
settings.TWITTER_SECRET,
)
# Then send them over there, durh.
tw_callback_url = request.build_absolute_uri(reverse('social_home'))
twitter_auth = twitter.get_authentication_tokens(callback_url=tw_callback_url)
request.session['twitter_auth'] = twitter_auth
return HttpResponseRedirect(twitter_auth['auth_url'])
从上面的视图中,用户被重定向到第二个视图,我希望在其中读取用户的时间线,我按以下方式进行 -
def social_home(request):
oauth_token_secret = request.session['twitter_auth']['oauth_token_secret']
oauth_token = request.session['twitter_auth']['oauth_token']
twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET, oauth_token, oauth_token_secret)
authorized_tokens = twitter.get_authorized_tokens(request.GET['oauth_verifier'])
user_tweets = twitter.get_home_timeline()
return render(request, "social_summary.html", {"user_tweets":user_tweets})
但在这里,我收到以下错误 - Twitter API 返回 401(未授权)、无效或过期令牌
请帮助我知道我错在哪里。
谢谢你的时间。