Twitter API返回401(未授权),处理您的请求时出错

时间:2013-10-13 08:16:27

标签: python twitter twitter-oauth twython

以下是获取关注者和更新状态的代码:

from twython import Twython,TwythonError
APP_KEY='mykey'
APP_SECRET='mysecret'
OAUTH_TOKEN='mytoken'
OAUTH_TOKEN_SECRET='mytokensecret'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
followers = twitter.get_followers_ids(screen_name = "darcythegreat")

for follower_id in followers:
    print follower_id

try:
    twitter.update_status(status='My first status using Twython')
except TwythonError as e:
    print e

这是我的推特LINK

运行后我收到以下错误:

python tweet.py 
previous_cursor
previous_cursor_str
next_cursor
ids
next_cursor_str
Twitter API returned a 401 (Unauthorized), An error occurred processing your request.

你能告诉我我错过了哪些步骤吗?

2 个答案:

答案 0 :(得分:2)

401可能会出现多种原因,其中一些原因与您编写的代码无关。一个常见的原因是您和Twitter的服务器之间的时钟时间不同。还有更多,这里是由@ episod / Twitter撰写的常见问题解答,可能有所帮助:https://dev.twitter.com/discussions/204

答案 1 :(得分:1)

<强> This StackOverflow answer worked for me.     我不得不更改帐户的权限。此外,这里给出的代码更简单: