Java examples for Social Media:Twitter
Query twitter by tag
import twitter4j.*; import twitter4j.conf.ConfigurationBuilder; import java.util.List; public class TwitterTest { public static void main(String[] args) { // Connect OAuth ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true)/* w w w . ja v a 2s . com*/ .setOAuthConsumerKey("0iGriIYgWLiQThhbuEPKbmgYV") .setOAuthConsumerSecret( "your key") .setOAuthAccessToken( "your key-your key") .setOAuthAccessTokenSecret( "your key"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { // Update Status //twitter.updateStatus("Testing Twitter API in Java"); // Get Timeline /*System.out.println("Home Timeline:"); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses ) { System.out.println(status.getUser().getName() + ": " + status.getText()); }*/ Query query = new Query("to:techcrunch"); QueryResult result = twitter.search(query); for (Status status : result.getTweets()) { System.out.println("@" + status.getUser().getScreenName() + ": " + status.getText()); } } catch (TwitterException te) { System.out.println(te); } } }