twittynumnum.BackwardGrinder.java Source code

Java tutorial

Introduction

Here is the source code for twittynumnum.BackwardGrinder.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package twittynumnum;

import java.util.List;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;

/**
 *
 * @author chrisgaubla
 */
public class BackwardGrinder {

    Twitter twitter;

    public BackwardGrinder(Twitter twitter) {
        this.twitter = twitter;
    }

    public void grind(String queryString) {

        try {
            Query query = new Query(queryString);
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText() + " - "
                            + tweet.getCreatedAt());
                }
            } while ((query = result.nextQuery()) != null);
            System.exit(0);
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
        }
    }
}