我正在使用twython推特 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.
知道我缺少什么吗?