我使用twython Twitter的API。
我获得的oauth_token和秘密如下 -
twitter = Twython(
settings.TWITTER_KEY,
settings.TWITTER_SECRET,
)
tw_callback_url = request.build_absolute_uri(reverse('save_twitter_token'))
twitter_auth = twitter.get_authentication_tokens(callback_url=tw_callback_url)
request.session['twitter_auth'] = twitter_auth
然后保存它与它签约后oauth_verifier
如下-
oauth_verifier = request.GET['oauth_verifier']
temp_o_token_secret = request.session['twitter_auth']['oauth_token_secret']
temp_o_token = request.session['twitter_auth']['oauth_token']
twitter = Twython(settings.TWITTER_KEY, settings.TWITTER_SECRET,
temp_o_token, temp_o_token_secret)
final_step = twitter.get_authorized_tokens(oauth_verifier)
final_oauth_token = final_step['oauth_token']
final_oauth_token_secret = final_step['oauth_token_secret']
一旦做到这一点,当我这样做 -
twitter = Twython(settings.TWITTER_KEY,
settings.TWITTER_SECRET,
acct_inst.oauth_token,
acct_inst.oauth_token_secret)
try:
user_timeline = twitter.get_home_timeline()
except TwythonError as e:
print user_timeline
我得到所需的输出。
但是,当我这样做 -
twitter = Twython(settings.TWITTER_KEY,
settings.TWITTER_SECRET,
ACCOUNT.oauth_token,
ACCOUNT.oauth_token_secret)
res = twitter.retweet(id=twitter_id)
其中twitter_id
是status_id
鸣叫的。
我得到401未经授权错误- *** TwythonAuthError: Twitter API returned a 401 (Unauthorized), An error occurred processing your request.
任何想法,我缺少什么?