Reputation: 870
Im new to twitter4j and processing.
I want to get the latest searched word from a list of words. I want this to be stored in the variable which will be queried. so:
PossibleWords[] ={"sad","happy","joyful"}
i would then want a string variable searchString to hold the latest tweeted tweet containing the word from the array. For example, if sad is tweeted just now, i want to get that tweet. So I need to test if any of the words from the array is in the latest tweeted words.
conceptually, I understand this, but any one have any suggestions on programming this? This in processing using twitter4j 3
Upvotes: 2
Views: 1016
Reputation: 1727
You should use the Twitter Streaming API, look at the code block that I pasted below:
private void GetTweetsByKeywords()
{
TwitterStream twitterStream = new TwitterStreamFactory(config).getInstance();
StatusListener statusListener = new StatusListener() {
private int count = 0;
private long originalTweetId = 0;
@Override
public void onStatus(Status status) {
// Here do whatever you want with the status object that is the
// tweet you got
} //end of the onStatus()
}; //end of the listener
FilterQuery fq = new FilterQuery();
String keywords[] = {"sad","happy","joyful"};
fq.track(keywords);
twitterStream.addListener(statusListener);
twitterStream.filter(fq);
}
Upvotes: 1
Reputation: 1862
Have you considered using the Twitter streaming API? This allows you to pass in up to 400 keywords and get a real time stream of tweets with any of those words in it. For example in twitter for J see here:
twitter4j - access tweet information from Streaming API
Replace the line
String keywords[] = {"France", "Germany"};
with
String keywords[] = {"sad","happy","joyful"};
and you should get a stream of tweets.
Upvotes: 0