【发布时间】:2013-10-06 09:03:39
【问题描述】:
我正在尝试让 python 使用 Twython 为我发送推文,但由于某种原因,我尝试的一切都不起作用。
我已关注Twython README,但仍然无法实现我想要的。
以下是我最近尝试的代码:
from twython import Twython, TwythonError
APP_KEY = "KEYHERE"
APP_SECRET = "SECRETHERE"
twitter = Twython(APP_KEY, APP_SECRET)
auth = twitter.get_authentication_tokens()
OAUTH_TOKEN = auth['oauth_token']
OAUTH_TOKEN_SECRET = auth['oauth_token_secret']
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
twitter.update_status(status='See how easy this was?')
except TwythonError as e:
print e
在运行上述代码时,我收到以下回溯错误:
Twitter API returned a 401 (Unauthorized), Invalid or expired token
有谁知道我做错了什么,更重要的是我该如何解决这个问题?
我没有足够的积分来获得赏金,但我非常感谢您的帮助!
提前致谢
编辑
Traceback (most recent call last):
File "C:\testtweet.py", line 20, in <module>
final_step = twitter.get_authorized_tokens(oauth_verifier)
File "C:\Python27\lib\site-packages\twython\api.py", line 313, in get_authorized_tokens
raise TwythonError('Unable to decode authorized tokens.')
TwythonError: Unable to decode authorized tokens.
以上是从@justhalf提供的代码中得到的回溯
非常感谢
【问题讨论】:
-
回答了这个问题。解决方案完全有效:)
-
代码返回
Twitter API returned a 401 (Unauthorized), Invalid or expired token的原因是在get_authentication_tokens()之后还需要'oauth_verifier'更多here还有this might be helpful -
check this answer 获取
oauth_verifier -
谢谢西蒙,我会去看看。
-
@SMNALLY 我能解决你的问题吗?
标签: python python-2.7 twitter twython