Example usage for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder

Introduction

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

Prototype

ConfigurationBuilder

Source Link

Usage

From source file:SocialMedia.CTwitter.java

public CTwitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("pHLUEo8VqYL1YJfXCwFoUumf2")
            .setOAuthConsumerSecret("7HWGZid7bNewVQjQbLt8MtSD8QLcBMOv8rfQ5Y6Bd8riIpkYf7")
            .setOAuthAccessToken("2855061284-40lddUpxDf46zlEZsiLMMekBU5r6L8dJFX3Lsfy")
            .setOAuthAccessTokenSecret("0TDs0JBRkA8CnY6YAavehMuvmuMRriM65BtTp6vptvNry");

    objTwitter = new TwitterFactory(cb.build()).getInstance();

}

From source file:soporte.ConfigTwitterStream.java

public ConfigTwitterStream() {
    cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);/*from  w  w  w .  j  av  a  2  s.c om*/
    cb.setOAuthConsumerKey(OAUTHCONSUMERKEY);
    cb.setOAuthConsumerSecret(OAUTHCONSUMERSECRET);
    cb.setOAuthAccessToken(OAUTHACCESSTOKEN);
    cb.setOAuthAccessTokenSecret(OAUTHACCESSTOKENSECRET);
}

From source file:source.TwitterSource.java

License:Apache License

/**
 * The initialization method for the Source. The context contains all the
 * Flume configuration info, and can be used to retrieve any configuration
 * values necessary to set up the Source.
 *
 * @param context Key-value store used to pass configuration information
 * throughout the system./*  www .  jav a  2 s. c om*/
 */
@Override
public void configure(Context context) {

    consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY);
    consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET);
    accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN);
    accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET);

    String swString = context.getString(TwitterSourceConstants.SW_LNG_LAT);
    String neString = context.getString(TwitterSourceConstants.NE_LNG_LAT);
    if (swString != null && neString != null) {
        String[] sw = swString.split(",");
        String[] ne = neString.split(",");
        if (sw.length == 2 && ne.length == 2) {
            for (int i = 0; i < 2; i++) {
                locations[0][i] = Double.parseDouble(sw[i].trim());
                locations[1][i] = Double.parseDouble(ne[i].trim());
            }
        } else {
            locations = null;
        }
    } else {
        locations = null;
    }

    String keywordString = context.getString(TwitterSourceConstants.KEYWORDS);
    if (keywordString != null) {
        keywords = keywordString.split(",");
        for (int i = 0; i < keywords.length; i++) {
            keywords[i] = keywords[i].trim();
        }
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);
    cb.setIncludeRTsEnabled(true);

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

}

From source file:storm.starter.spout.Q2FetchTweetSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;/* w w w. ja  v a  2  s.  c  o m*/

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    twitterStream.sample();
}

From source file:storm.starter.spout.Q2SeqTwitterSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;// w  w w . ja v a 2s  .  c o m

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    FilterQuery query = new FilterQuery();
    query.track(keyWords);
    query.language(new String[] { "en" });
    twitterStream.filter(query);
}

From source file:storm.starter.spout.TwitterKeywordsSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;/*from w  w w .  java2 s .co m*/

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {
            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);
    _twitterStream = twitterStream;

    if (keyWords.length == 0) {

        twitterStream.sample();
    }

    else {
        // TODO: Adjust the query below to also track locations and languages.
        FilterQuery query = new FilterQuery();
        query.track(keyWords);
        query.language(new String[] { "en" });

        twitterStream.filter(query);

    }

}

From source file:storm.starter.spout.TwitterNoKeywordSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;/*w  w  w  .j  a v a 2  s  . c  o m*/

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    twitterStream.sample();

    FilterQuery query = new FilterQuery();
    //query.count(1000000);
    query.language(new String[] { "en" });
    twitterStream.filter(query);
}

From source file:storm.starter.spout.TwitterRandomEnglishSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;//from   w w w  .  j  a va2s .c  om

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {
            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);
    _twitterStream = twitterStream;

    FilterQuery query = new FilterQuery();
    //query.track(new String[] {"#politics"});
    //query.language(new String[]{"en"});
    twitterStream.sample();

    /*
    if (keyWords.length == 0) {
       twitterStream.sample();
    }
            
    else {
       // TODO: Adjust the query below to also track locations and languages.
       FilterQuery query = new FilterQuery();
       query.track(keyWords);
       query.language(new String[]{"en"});
       //query.locations(wholeWorldBoundingBox);
               
       twitterStream.filter(query);   
    }
    */

}

From source file:storm.starter.trident.homework.spouts.TwitterSampleSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context) {
    queue = new LinkedBlockingQueue<Status>(1000);

    StatusListener listener = new StatusListener() {

        @Override//from  w  w  w.ja v  a2 s. com
        public void onStatus(Status status) {

            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    if (keyWords.length == 0) {

        twitterStream.sample();
    } else {

        FilterQuery query = new FilterQuery().track(keyWords);
        twitterStream.filter(query);
    }

}

From source file:storm.twitter.spout.TwitterSampleSpout.java

License:Apache License

/**
 * {@inheritDoc}//from  www.java2  s. c o m
 *
 * The method receives tweets from Twitter Streaming API and puts them into queue variable.
 *
 * <p>The method is called when a task for this component is initialized within a worker on the cluster.
 * It provides the spout with the environment in which the spout executes.
 *
 * @param conf The configuration of Apache Storm for the spout.
 * @param context The context contains information about the place of a task in the topology. It contains
 *                information about the task id, component id, I/O information, etc.
 * @param collector The collector is used to emit tuples to the output stream of the spout.
 */
@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    // Create queue of Strings for tweets
    queue = new LinkedBlockingQueue<String>(1000);
    _collector = collector;

    StatusListener listener = new StatusListener() {

        // Get json from Twitter API and put it to queue
        @Override
        public void onStatus(Status status) {
            String json = TwitterObjectFactory.getRawJSON(status);
            queue.offer(json);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }

    };

    // Create twitterStream
    TwitterStream twitterStream = new TwitterStreamFactory(
            new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance();

    // Twitter API configuration
    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);

    // if there is no keywork filter - get all 1% of tweets from API
    if (keyWords.length == 0) {
        twitterStream.sample();
    }
    // filter tweets from the stream
    else {
        FilterQuery query = new FilterQuery().track(keyWords);
        twitterStream.filter(query);
    }
}