We are about to switch to a new forum software. Until then we have removed the registration on this forum.
How do I retrieve the latest tweets for a hash tag? Im using twitter4j 3 and processing 2
So far I can only retrieve only a given number of tweets, but I would like to retrieve the latest tweets for the hash tag #willsmith for example:
Heres my code:
void connectTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("XXXXXXX");
cb.setOAuthConsumerSecret("XXXXXXX");
cb.setOAuthAccessToken("XXXXXXX");
cb.setOAuthAccessTokenSecret("XXXXXX");
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
}
// Get your tweets
void getTimeline() {
try {
statuses = twitter.getHomeTimeline();
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status:statuses) {
println(status.getUser().getName() + ": " + status.getText());
}
}
// Search for tweets
void getSearchTweets() {
try {
Query query = new Query("#willsmith");
query.setCount(100);
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
println("@" + status.getUser().getScreenName() + ":" + status.getText());
}
}
catch (TwitterException e) {
println("Search tweets: " + e);
}
}
Any suggestions?
Answers
maybe getSince and setSince could help with that, have you tried?
http://twitter4j.org/javadoc/twitter4j/Query.html#getSince()
Questions about libraries belong to the proper category, not to the default one! (We should find a way to force to choose one!)
Moved.