Skip to content

Instantly share code, notes, and snippets.

@milindjagre
Last active December 9, 2020 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milindjagre/96ff54bf5781533b2762ca3239b7d107 to your computer and use it in GitHub Desktop.
Save milindjagre/96ff54bf5781533b2762ca3239b7d107 to your computer and use it in GitHub Desktop.
package com.milind.twitter.trends;
import java.io.IOException;
import twitter4j.Trend;
import twitter4j.Trends;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
/**
*
* @author Milind
*/
public class TwitterTrendingTopics {
public static void main(String[] args) throws IOException, TwitterException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("3jmA1BqasLHfItBXj3KnAIGFB")
.setOAuthConsumerSecret("imyEeVTctFZuK62QHmL1I0AUAMudg5HKJDfkx0oR7oFbFinbvA")
.setOAuthAccessToken("265857263-pF1DRxgIcxUbxEEFtLwLODPzD3aMl6d4zOKlMnme")
.setOAuthAccessTokenSecret("uUFoOOGeNJfOYD3atlcmPtaxxniXxQzAU4ESJLopA1lbC");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Trends trends = twitter.getPlaceTrends(1);
int count = 0;
for (Trend trend : trends.getTrends()) {
if (count < 10) {
System.out.println(trend.getName());
count++;
}
}
}
}
@milindjagre
Copy link
Author

This file gives you the top 10 worldwide trending topics on twitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment