使用 Oauth2 在 tweepy 中使用 api.update_status 方法时出错 [英] Error using api.update_status method in tweepy using Oauth2
问题描述
这是我的代码:-我已经仔细检查了所有的身份验证参数.
Here is my code:- I have double checked all the auth parameters.
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后出现以下错误:-
Saved the file in home folder as status.py after running python status.py follwing error comes:-
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.
请帮帮我
推荐答案
我能够使用 tweepy 进行身份验证,不过我的代码中有额外的一行,它可能有助于您将代码更改为:
I am able to authenticate using tweepy, I have an extra line in my code though, it might help for you to change your code to this:
import tweepy
from tweepy import OAuthHandler
然后继续执行其余代码.还要在您的代码中添加一行以打印到 shell 以显示您的连接,如下所示:
then proceede with the rest of your code. Also add a line in your code to print out to the shell to show your connect as follows:
打印 api.me().name
确保您在上面看到的行紧跟在 api = tweepy.API(auth)
Make sure the line you see above this is right after api = tweepy.API(auth)
这篇关于使用 Oauth2 在 tweepy 中使用 api.update_status 方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!