Example usage for twitter4j Query until

List of usage examples for twitter4j Query until

Introduction

In this page you can find the example usage for twitter4j Query until.

Prototype

String until

To view the source code for twitter4j Query until.

Click Source Link

Usage

From source file:org.todoke.countsearch.Main.java

License:Apache License

static int search(String term, String date) {
    Callback callback = new Callback(new String[] { term });
    Twitter twitter = new TwitterFactory().getInstance();
    int count = 0;
    try {//from w ww.ja  v  a2  s  .c  o m
        int page = 1;
        List<Tweet> tweets;
        do {
            Query query = new Query(term);
            query.rpp(100);
            query.until(date);
            query.setPage(page);
            QueryResult qs = twitter.search(query);
            tweets = qs.getTweets();
            boolean outOfRange = false;
            for (Tweet tweet : tweets) {

                try {
                    if (tweet.getCreatedAt().after(format.parse(date))) {
                        callback.increment(tweet.getText(), tweet.getCreatedAt());
                        count++;
                    } else {
                        //                        System.out.println(tweet.getCreatedAt());
                        outOfRange = true;
                    }
                } catch (ParseException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
            }
            if (outOfRange) {
                break;
            }
            page++;
        } while (tweets.size() != 0);
    } catch (TwitterException e) {
        e.printStackTrace();
        //            System.exit(-1);
    }
    return count;
}