python - 如何获取特定时间范围内推文的twitter数据?

标签 python json twitter tweepy

我要在我的代码中添加什么,才能在推文数据回到特定点时强制程序停止打印数据。例如,如何在运行此程序的一个月内获取所有关于 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

关于python - 如何获取特定时间范围内推文的twitter数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978429/

相关文章:

objective-c - 在 iOS5 中使用 Twitter 框架提示登录警报?

java - com.google.gson.JsonSyntaxException : java. lang.IllegalStateException : Not a JSON Array: {"type" :"Point" ,"coordinates":[-122. 3964485,37.7912561]}

ruby-on-rails - Twitter 卡片验证器在开发时出现错误

python - scapy:无法将带有子键的字典传递给 ByteEnum 字段

python 3 : Make itemgetter sort by string length

json - 使用 Golang 修改 JSON 文件

php - 以数组形式返回验证错误并更改为 json

rtweet create_token 在需要 TRUE/FALSE 的地方缺少值

python - Python 的标准库中是否有 linspace 函数?

python - 在 python3 中编译 SCons