我正在尝试在英文监控中为关键字提供所有推文。我重新定义了on_status函数来执行此操作。我在运行代码时没有遇到任何错误,但无论出于何种原因,推文都没有被打印出来,正如预期的那样。我在推特上发了自己帐户中的关键字。任何建议有帮助!提前致谢。请告诉我,如果有更多信息我可以提供澄清。
import tweepy
import pymongo
from pymongo import MongoClient
client = MongoClient('localhost', 27017)
db = client['Twitter_DB']
collection_Authentication = db['authentication']
consumer_key = collection_Authentication.find_one({"name" : "consumer_key"})
["value"]
consumer_secret = collection_Authentication.find_one({"name" :
"consumer_secret"})["value"]
access_token = collection_Authentication.find_one({"name" : "access_token"})
["value"]
access_secret = collection_Authentication.find_one({"name" : "access_secret"})
["value"]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
#-----class StdOutListener() Definition-----
class StdOutListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
return True
def on_error(self, status_code):
print(str(status_code))
return True
def on_timeout(self):
print("Timeout...")
return True
if __name__ == '__main__':
listener = StdOutListener()
stream = tweepy.Stream(auth, listener)
stream.filter(track="ethereum", languages="en")