Search Tweet from Twitter - Java Social Media

Java examples for Social Media:Twitter

Description

Search Tweet from Twitter

Demo Code

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;

import java.util.List;

public class Search {
    public static void main(String[] args) {
        if (args.length < 1) {
            System.exit(-1);/*from   w  ww .j  a v  a  2  s.  com*/
        }
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            QueryResult result = twitter.search(new Query(args[0]));
            List<Tweet> tweets = result.getTweets();
            for (Tweet tweet : tweets) {
                System.out.println("@" + tweet.getFromUser() + " - "
                        + tweet.getText());
            }
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println(te.getMessage());
            System.exit(-1);
        }
    }
}

Related Tutorials