2015-03-31 70 views
0

我正在使用twitter4j流api獲取特定哈希標籤的鳴叫,但獲取我所需的哈希標籤和其他主題標籤只有10條鳴叫,我獲得的鳴叫數最多爲5000條。使用twitter4j獲取特定哈希標記的鳴叫

爲什麼我只收到10條推文和5000條推文呢?

+0

你可以在這裏發佈你的代碼嗎? – Logicbomb 2015-03-31 12:17:08

回答

0
ConfigurationBuilder cb = new ConfigurationBuilder(); 
cb.setDebugEnabled(true) 
    .setOAuthConsumerKey(" ") 
    .setOAuthConsumerSecret(" ") 
    .setOAuthAccessToken(" ") 
    .setOAuthAccessTokenSecret(" "); 
Twitter twitter = new TwitterFactory(cb.build()).getInstance(); 
Query query = new Query("hashtag"); 
int numberOfTweets = 7; 
long lastID = Long.MAX_VALUE; 
ArrayList<Status> tweets = new ArrayList<Status>(); 

while (tweets.size() < numberOfTweets) { 
    if (numberOfTweets - tweets.size() > 100) 
    query.setCount(100); 
    else 
    query.setCount(numberOfTweets - tweets.size()); 
    try { 
    QueryResult result = twitter.search(query); 
    tweets.addAll(result.getTweets()); 
    System.out.println("Gathered " + tweets.size() + " tweets"+"\n"); 
    for (Status t: tweets) 
     if(t.getId() < lastID) 
      lastID = t.getId(); 

    } 

    catch (TwitterException te) { 
    System.out.println("Couldn't connect: " + te); 
    }; 
    query.setMaxId(lastID-1); 
} 
for (int i = 0; i < tweets.size(); i++) { 
    Status t = (Status) tweets.get(i); 

// GeoLocation loc = t.getGeoLocation(); 

    String user = t.getUser().getScreenName(); 
    String msg = t.getText(); 
    //String time = ""; 
    //if (loc!=null) { 
    //Double lat = t.getGeoLocation().getLatitude(); 
    //Double lon = t.getGeoLocation().getLongitude();*/ 
    System.out. println(i + " USER: " + user + " wrote: " + msg + "\n"); 
    } 
    //else 
    //System.out.println(i + " USER: " + user + " wrote: " + msg+"\n"); 
+0

這是我的代碼@Jawa – 2015-04-01 05:58:26