Gligorijevic
Gligorijevic

Reputation: 67

twitter4j multiple queries

Is there any way to make query in twitter4j search for more that one keyword?

Like instead of making more queries in my program I can make one which does it all, so I will have only one big stream of tweets that I can read?

I guess it would be something to replace this:

Query query1 = new Query("SOME RANDOM TEXT1" );
Query query2 = new Query("SOME RANDOM TEXT2" );
Query query3 = new Query("SOME RANDOM TEXT3" );
Query query4 = new Query("SOME RANDOM TEXT4" );
...

Upvotes: 1

Views: 1753

Answers (1)

Pete
Pete

Reputation: 580

Create a FilterQuery object and then set the items to track

FilterQuery filterQuery = new FilterQuery();

Create an array of items to track

String[] itemsToTrack = {"python", "java", "php"};

Set the items to track using FilterQuerys' track method.

filterQuery.track(itemsToTrack);

Assuming you have already created Twitter/TwitterStream object, use the filter method to start streaming using the FilterQuery object just created.

twitterStream.filter(filterQuery); 

Hope this helps.

Upvotes: 5

Related Questions