2016-05-04 68 views
0

我想在Python中使用tweepy獲取舊推文數據(大約2個月大)。我試過,直到參數但沒有成功。有沒有人在tweepy或其他API中得到解決方法。使用Python的舊推文Tweepy

for id,tweet in enumerate (tweepy.Cursor(api.search, q='SpecificWord', since="2016-04-26", until="2016-04-28", lang="en", include_retweets=False ).items(200)): 
    #Write a row to the csv file 
    CSVW.writerow([tweet.created_at, tweet.retweet_count, tweet.text.encode('utf-8')]) 

回答

3

這是不可能的。 The docs on the Twitter API are very clear

Twitter Search API搜索最近7天發佈的最近推文的樣本。

沒有辦法搜索更遠的地方。

+0

感謝特倫斯,你推薦我從哪裏可以下載基於「SpecificWord」歷史鳴叫數據,然後利用它來進行進一步的分析任何開源網站? –

+0

獲取歷史數據的唯一地方是https://www.gnip.com/ - 或者今天開始收集數據:-) –

-1

有兩種方法可以獲得較舊的推文。

  1. 您將獲得Tweepy的分支版本,該版本支持多個身份驗證處理程序。 Here is an instruction關於如何使用它(不幸只與Python 2.7)。或者您使用this ratetime Tweepy限制器。但使用Twitter API,您可以獲得的最早的數據大概是7天。

  2. 另一種方法是使用GetOldTweets-python,它也適用於Python 3.下面是一個關於如何使用它的例子。

首先安裝LXML(版本3.5)& pyquery版本1.2.10):

pip3 install lxml==3.5.0 
pip3 install pyquery==1.2.10 

然後下載GetOldTweets,Python和文件夾got3複製到你的網站包文件夾,然後運行Python。

import got3 

max_tweets = 3 

tweetCriteria = got3.manager.TweetCriteria().setUntil("2016-01-31").setQuerySearch("bitcoin").setMaxTweets(max_tweets) 

for i in range(max_tweets): 
    tweet = got3.manager.TweetManager.getTweets(tweetCriteria)[i] 
    print(tweet.id) 
    print(tweet.username) 
    print(tweet.text) 
    print(tweet.date) 

現在,您將從2016年獲得推文!

693584301917655041 
bitcoinfirehose 
Teenagers are using untraceable currency Bitcoin to buy dangerous drugs online http://ift.tt/20eIDwU #reddit #bitcoin 
2016-01-31 00:59:18 

693584300265070593 
bitcoinfirehose 
Hey guys I've seen a need to cashout to Visa. So I created a site to get moneypak codes via Bitcoin ! Please come check it out! … 
2016-01-31 00:59:18 

693584286210002944 
b1eedr 
Bitcoin 2.0: Fantasy Or Inevitability? https://www.cryptocoinsnews.com/bitcoin-2-0-fantasy-or-inevitability/ @CryptoCoinsNews 
2016-01-31 00:59:14