2017-07-07 1146 views
2

我在我的代码中放入了什么东西,以便我可以强制程序在推文数据回到某个特定点时停止打印数据。例如,如何从一个月内获得有关Verratti的所有推文?如何在特定时间范围内获取推文的Twitter数据?

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']) 

回答

0

不错的问题。事实证明,Twitter API只允许您从当前日期起回顾一周。尽管如此,有人制作了一个github库,可以使用twitter的高级搜索功能搜索任何时间范围,甚至不必担心整个身份验证过程。

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

相关问题