通过twython发布转发给出401,而我可以轻松访问时间轴 [英] Posting a retweet via twython gives 401 whereas I can easily access the timeline
本文介绍了通过twython发布转发给出401,而我可以轻松访问时间轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 twython twitter API。
I am using twython twitter API.
我正在获取oauth_token和秘密如下 -
I am obtaining the oauth_token and secret as follows -
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
如下 -
and then saving it after signing it with oauth_verifier
as follows -
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']
一旦这样做,当我这样做 -
Once this is done, when I do -
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
我得到所需的输出。
但是当我这样做 -
But when I do -
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
一个tweet。
where twitter_id
is the status_id
of a tweet.
我获得401未经授权的错误 - *** TwythonAuthError:Twitter API返回401(未经授权),处理您的请求。
I get 401 unauthorized error - *** TwythonAuthError: Twitter API returned a 401 (Unauthorized), An error occurred processing your request.
任何想法我缺少什么?
推荐答案
尝试从状态而不是 id
这篇关于通过twython发布转发给出401,而我可以轻松访问时间轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文