develop1 develop1 - 1 year ago 45
Java Question

Twitter Search for all content instead of relevence

I am working on a web application that gets all tweets within a time period for a specific keyword. The Twitter4J API does not return all tweets but the most relevant. Is there a way to get all tweets for a specific keyword? I have tried setting the query result type to

, but that is still unsuccessful at getting everything.

I know about Twitters streaming API but I am not able to collect data for a period of time. The search keyword can be for anything so collecting and storing so much data is not reasonable.

public static void main(String[] args) throws TwitterException {

Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query("(amazon) AND (stock)");

QueryResult result =;

int numberOfTweets = 0;
for (Status status : result.getTweets()) {
System.out.println("@" + status.getUser().getScreenName() + "-" + status.getCreatedAt() + ":");


Answer Source

From the documentation on the Search API

Please note that Twitter’s search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.

You cannot get everything.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download