Is there any way to get tweets containing a keyword in java? I want to download as many as possible, I have seen a java library twitter4j but it gives only small number of tweets.
Asked
Active
Viewed 1,154 times
2 Answers
1
Read the documentation of twitter api https://dev.twitter.com/docs/api/1/get/search Its rate limited though. I dont think there is a way around it. The rate limiting varies with open search apis and the ones that require authentication. http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&result_type=mixed (Note - this link is copied from twiter api webpage)

Bhanu Kaushik
- 876
- 6
- 25
1
You can set the page size and number using Twitter4J to request more tweets.
public static void main(String[] args) throws TwitterException {
Twitter twitter = new TwitterFactory().getInstance();
for (int page = 1; page <= 10; page++) {
System.out.println("\nPage: " + page);
Query query = new Query("#MyWorstFear"); // trending right now
query.setRpp(100);
query.setPage(page);
QueryResult qr = twitter.search(query);
List<Tweet> qrTweets = qr.getTweets();
if(qrTweets.size() == 0) break;
for(Tweet t : qrTweets) {
System.out.println(t.getId() + " - " + t.getCreatedAt() + ": " + t.getText());
}
}
}

Bill the Lizard
- 398,270
- 210
- 566
- 880