2017-07-07 1141 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

相關問題