如何在一定时间范围内获取推文的推特数据?



我在代码中放了什么,以便在推文将数据返回到某个点时强制程序停止打印数据。例如,我如何在运行此内容后的一个月内获取有关 Verratti 的所有推文?

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
access_token = the code
access_token_secret = the code
consumer_key = the code
consumer_secret = the code

#print
class StdOutListener(StreamListener):
def on_data(self, data):
print (json.loads(data)['text'])
return True
def on_error(self, status):
print (status)
#find
if __name__ == '__main__':
#This handles Twitter authetification and the connection to Twitter         Streaming API
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
#This line filter Twitter Streams to capture data by the keywords:     'python', 'javascript', 'ruby'
stream.filter(track=['Verratti'])

好问题。事实证明,Twitter API 只允许你从当前日期回顾一周。不过有一种方法可以解决这个问题,有人制作了一个 github 库,可以使用 Twitter 的高级搜索功能搜索任何时间范围,你甚至不必为整个身份验证过程而烦恼。

看看吧: https://github.com/Jefferson-Henrique/GetOldTweets-python

最新更新