Example usage for twitter4j AsyncTwitterFactory AsyncTwitterFactory

List of usage examples for twitter4j AsyncTwitterFactory AsyncTwitterFactory

Introduction

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

Prototype

public AsyncTwitterFactory() 

Source Link

Document

Creates an AsyncTwitterFactory with the root configuration, with no listener.

Usage

From source file:org.primefaces.examples.service.TwitterAPIService.java

License:Apache License

public List<Status> asyncSearch(String query) {

    TwitterListener listener = new TwitterAdapter() {
        @Override//from   w  w w. jav a  2  s.c  o  m
        public void searched(QueryResult queryResult) {
            asyncTweets = queryResult.getTweets();
        }

        @Override
        public void onException(TwitterException e, TwitterMethod method) {
            logger.severe(e.getMessage());
        }
    };

    AsyncTwitter twitter = new AsyncTwitterFactory().getInstance();
    twitter.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret);
    twitter.setOAuthAccessToken(new AccessToken(access_token, access_token_secret));
    twitter.addListener(listener);
    Query q = new Query(query);
    twitter.search(q);
    return asyncTweets;
}

From source file:twitter4j.examples.async.AsyncUpdate.java

License:Apache License

public static void main(String[] args) throws InterruptedException {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.AsyncUpdate text");
        System.exit(-1);//from  w  ww. j  av  a2s.c  o  m
    }
    AsyncTwitterFactory factory = new AsyncTwitterFactory();
    AsyncTwitter twitter = factory.getInstance();
    twitter.addListener(new TwitterAdapter() {
        @Override
        public void updatedStatus(Status status) {
            System.out.println("Successfully updated the status to [" + status.getText() + "].");
            synchronized (LOCK) {
                LOCK.notify();
            }
        }

        @Override
        public void onException(TwitterException e, TwitterMethod method) {
            if (method == UPDATE_STATUS) {
                e.printStackTrace();
                synchronized (LOCK) {
                    LOCK.notify();
                }
            } else {
                synchronized (LOCK) {
                    LOCK.notify();
                }
                throw new AssertionError("Should not happen");
            }
        }
    });
    twitter.updateStatus(args[0]);
    synchronized (LOCK) {
        LOCK.wait();
    }
}