2013-12-08 42 views
1

我已經使用twitter4j構建了一個應用程序,當我輸入關鍵字時,它會引入一串推文,將地理位置從推文(或回落到配置文件位置),然後使用ammaps映射它們。問題是我只收到一小部分推文,這裏有一些限制嗎?我有一個數據庫去收集鳴叫數據,這麼快就會有一個體面的數額,但我很好奇,爲什麼我只能在過去的12個小時內收到鳴叫?通過twitter API獲取所有推文,而不僅僅是最近的推文(使用twitter4j - Java)

例如,如果我用我的用戶名進行搜索,我只會收到一條今天發送的推文。

感謝您的任何信息!

編輯:我明白Twitter不允許公衆訪問firehose ..更多爲什麼我只限於發現最近的推文?

回答

2

你需要不斷重做查詢,每次重置maxId,直到你沒有得到任何回報。你也可以使用setSince和setUntil。

一個例子:

Query query = new Query(); 
query.setCount(DEFAULT_QUERY_COUNT); 
query.setLang("en"); 
// set the bounding dates 
query.setSince(sdf.format(startDate)); 
query.setUntil(sdf.format(endDate)); 

QueryResult result = searchWithRetry(twitter, query); // searchWithRetry is my function that deals with rate limits 

while (result.getTweets().size() != 0) { 

    List<Status> tweets = result.getTweets(); 
    System.out.print("# Tweets:\t" + tweets.size()); 
    Long minId = Long.MAX_VALUE; 

    for (Status tweet : tweets) { 
    // do stuff here    
     if (tweet.getId() < minId) 
     minId = tweet.getId(); 
    } 
    query.setMaxId(minId-1); 
    result = searchWithRetry(twitter, query); 

}

+0

你能分享代碼嗎? :)我有同樣的問題 –

+0

@ThusithaThilinaDayaratne你在找什麼代碼? Twitter4j API有詳細記錄。 – betseyb

1
Really it depend on which API system you are using. I mean Streaming or Search API. In the search API there is a parameter (result_type) that is an optional parameter. The values of this parameter might be followings: 

    * mixed: Include both popular and real time results in the response. 
    * recent: return only the most recent results in the response 
    * popular: return only the most popular results in the response. 

The default one is the mixed one. 

As far as I understand, you are using the recent one, that is why; you are getting the recent set of tweets. Another issue is getting low volume of tweets that have the geological information. Because there are very few users added the geological information to their profile, you are getting very few tweets. 
+0

哎,真的很感謝的答覆。好的,這是有道理的。我正在剝離位置,所以我明白我會變得更少,但即使在我的代碼達到if(tweet.getGeoLocation!= null)的點之前,我仍然只獲得15個推文的列表。你知道是否有什麼要做,以達到這個限制,還是它是由Twitter的限制..非消防站有點限制? – brdu

相關問題