【发布时间】:2015-04-09 08:44:51
【问题描述】:
我正在尝试使用 Tweepy 检索 Twitter 数据,使用下面的代码,但我返回 401 错误,我重新生成访问和秘密令牌,并且出现了相同的错误。
#imports
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
#setting up the keys
consumer_key = 'xxxxxxx'
consumer_secret = 'xxxxxxxx'
access_token = 'xxxxxxxxxx'
access_secret = 'xxxxxxxxxxxxx'
class TweetListener(StreamListener):
# A listener handles tweets are the received from the stream.
#This is a basic listener that just prints received tweets to standard output
def on_data(self, data):
print (data)
return True
def on_error(self, status):
print (status)
#printing all the tweets to the standard output
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
stream = Stream(auth, TweetListener())
t = u"#سوريا"
stream.filter(track=[t])
【问题讨论】:
-
您是否在您的 Twitter 帐户中授权了该应用程序? [帮助链接][1] [1]:stackoverflow.com/questions/19095257/…
-
不幸的是,我仍然有同样的错误。
-
我也尝试使用 twitter 字段检查登录,但没有用。任何帮助!!!
-
我猜是你机器的日期和时间问题,请检查它们是否更新?如果您的凭据不正确或者您使用的是过时版本的 tweepy,这很常见
-
哦,我找到了解决方案。在这个链接link,所有关于国家,时间设置在您的计算机中。谢谢所有