我正在使用状态/过滤器,并尝试根据参数" filter_level"从twitter流中过滤推文。
query = ["Donald Trump","Cristiano Ronaldo"]
numberOfTweets = 1000
dictOfTweets ={}
twitter_api = oauth_login()
twitter_stream = twitter.TwitterStream(auth=twitter_api.auth)
for q in query:
stream = twitter_stream.statuses.filter(track=q,max_count=numberOfTweets,languages= ['en'],filter_level=['medium'])
for tweet in stream:
if tweet.get('text',0) == 0:
continue
dictOfTweets.setdefault(q,[]).append(tweet['text'])
我仍然收到有关filter_level =" low"的推文。如果有人能说出我遗失或做错的事情,那将会非常有帮助吗?
答案 0 :(得分:0)
您需要在身份验证
时放入(语言= ['en'],filter_level = ['medium'])query = ["Donald Trump","Cristiano Ronaldo"]
numberOfTweets = 1000
dictOfTweets ={}
twitter_api = oauth_login()
twitter_stream = twitter.TwitterStream(auth=twitter_api.auth, ,languages= ['en'],filter_level=['medium'])
for q in query:
stream = twitter_stream.statuses.filter(track=q,max_count=numberOfTweets)
for tweet in stream:
if tweet.get('text',0) == 0:
continue
dictOfTweets.setdefault(q,[]).append(tweet['text'])