这是我的代码: - 我仔细检查了所有auth参数。
import tweepy
CONSUMER_KEY ='#Omitted - you should not publish your actual key'
CONSUMER_SECRET ='#Omitted - you should not publish your actual secret'
ACCESS_KEY='#Omitted - you should not publish your access key'
ACCESS_SECRET = '#Omitted - you should not publish your access secret'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.update_status('Tweeting from command line')
将文件保存在主文件夹中,状态为status.py 运行python status.py之后出现以下错误: -
Traceback (most recent call last):
File "status.py", line 14, in <module>
api.update_status('Tweeting from command line')
File "/usr/local/lib/python2.7/dist-packages/tweepy-1.10-py2.7.egg/tweepy/binder.py", line 185, in _call
return method.execute()
File "/usr/local/lib/python2.7/dist-packages/tweepy-1.10-py2.7.egg/tweepy/binder.py", line 168, in execute
raise TweepError(error_msg, resp)
tweepy.error.TweepError: Could not authenticate with OAuth.
请帮帮我
答案 0 :(得分:2)
我在相同条件下收到此错误 - 使用tweepy,我的所有密钥/秘密都被正确复制和粘贴。问题是我服务器上的时间。运行ntpdate -b pool.ntp.org
之后我就好用了tweepy。
答案 1 :(得分:0)
我可以使用tweepy进行身份验证,但我的代码中还有一行,您可以将代码更改为:
import tweepy
from tweepy import OAuthHandler
然后继续执行其余的代码。还要在代码中添加一行以打印到shell以显示连接,如下所示:
print api.me().name
确保您在上面看到的行正好在api = tweepy.API(auth)
答案 2 :(得分:0)
试试api.update_status(status='Tweeting from command line')
。它帮助了我。