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:org.apache.camel.component.twitter.TwitterConfiguration.java

License:Apache License

/**
 * Builds a Twitter4J Configuration using the OAuth params.
 *
 * @return Configuration/*from w  w w .  j a va2 s  .co m*/
 */
public Configuration getConfiguration() {
    checkComplete();
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();
    confBuilder.setOAuthConsumerKey(consumerKey);
    confBuilder.setOAuthConsumerSecret(consumerSecret);
    confBuilder.setOAuthAccessToken(accessToken);
    confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
    confBuilder.setUseSSL(useSSL);
    if (getHttpProxyHost() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyHost());
    }
    if (getHttpProxyUser() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyUser());
    }
    if (getHttpProxyPassword() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyPassword());
    }
    if (httpProxyPort != null) {
        confBuilder.setHttpProxyPort(httpProxyPort);
    }

    return confBuilder.build();
}

From source file:org.apache.nutch.protocol.http.api.HttpBase.java

License:Apache License

private TwitterFactory getTwitterFactoryWithConfigParams(String consumerKey, String consumerSecret,
        String accessToken, String accessTokenSecret) {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret)
            .setPrettyDebugEnabled(true);
    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf;//from   w  ww .  j a v a2  s  .  c  om
}

From source file:org.apache.s4.example.twitter.TwitterInputAdapter.java

License:Apache License

public void connectAndRead() throws Exception {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    Properties twitterProperties = new Properties();
    File twitter4jPropsFile = new File(System.getProperty("user.home") + "/twitter4j.properties");
    if (!twitter4jPropsFile.exists()) {
        logger.error(//from w  w  w.j a  va 2  s.  co m
                "Cannot find twitter4j.properties file in this location :[{}]. Make sure it is available at this place and includes user/password credentials",
                twitter4jPropsFile.getAbsolutePath());
        return;
    }
    twitterProperties.load(new FileInputStream(twitter4jPropsFile));

    cb.setDebugEnabled(Boolean.valueOf(twitterProperties.getProperty("debug")))
            .setUser(twitterProperties.getProperty("user"))
            .setPassword(twitterProperties.getProperty("password"));
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener statusListener = new StatusListener() {

        @Override
        public void onException(Exception ex) {
            logger.error("error", ex);
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            logger.error("error");
        }

        @Override
        public void onStatus(Status status) {
            messageQueue.add(status);

        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            logger.error("error");
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            logger.error("error");
        }
    };
    twitterStream.addListener(statusListener);
    twitterStream.sample();

}

From source file:org.apache.solr.handler.dataimport.TwitterEntityProcessor.java

License:Apache License

public void init(Context context) {
    super.init(context);

    // get parameters
    String consumerKey = getStringFromContext("consumerKey", null);
    String consumerSecret = getStringFromContext("consumerSecret", null);
    String accessToken = getStringFromContext("accessToken", null);
    String accessTokenSecret = getStringFromContext("accessTokenSecret", null);

    // connect to twitter
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);

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

    // initiate the search
    String criteria = getStringFromContext("criteria", null);
    since = context.replaceTokens("${dih.last_index_time}");
    query = new Query(criteria);
    //query.setSince(since.substring(0, since.indexOf(" ")).trim());      
    query.setSince("2015-02-12");

    index = 0;/*  w  ww  . java2s  .c  o m*/

    logConfig();
}

From source file:org.apache.storm.starter.spout.Q2TwitterSampleSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;//from  w  ww . j  a  va  2s. com

    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 = 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);
        query.language(new String[] { "en" });
        query.track(new String[] { "job", "vote", "local", "Clinton", "Trump", "debate", "tech",
                "TheWalkingDead", "android", "Election", "USA", "GOT7", "Empire", "Apple", "ISIS", "election",
                "Football", "iPhone", "Amazon", "uber" });
        _twitterStream.filter(query);
    }

}

From source file:org.apache.streams.twitter.processor.FetchAndReplaceTwitterProcessor.java

License:Apache License

protected Twitter getTwitterClient() {
    if (this.client == null) {
        String baseUrl = "https://api.twitter.com:443/1.1/";

        ConfigurationBuilder builder = new ConfigurationBuilder()
                .setOAuthConsumerKey(config.getOauth().getConsumerKey())
                .setOAuthConsumerSecret(config.getOauth().getConsumerSecret())
                .setOAuthAccessToken(config.getOauth().getAccessToken())
                .setOAuthAccessTokenSecret(config.getOauth().getAccessTokenSecret())
                .setIncludeEntitiesEnabled(true).setJSONStoreEnabled(true).setAsyncNumThreads(1)
                .setRestBaseURL(baseUrl).setIncludeMyRetweetEnabled(Boolean.TRUE)
                .setPrettyDebugEnabled(Boolean.TRUE);

        this.client = new TwitterFactory(builder.build()).getInstance();
    }//from ww w.  ja  va2 s.c o  m
    return this.client;
}

From source file:org.apache.streams.twitter.provider.TwitterTimelineProvider.java

License:Apache License

public Twitter getTwitterClient() {
    String baseUrl = "https://api.twitter.com:443/1.1/";

    ConfigurationBuilder builder = new ConfigurationBuilder()
            .setOAuthConsumerKey(config.getOauth().getConsumerKey())
            .setOAuthConsumerSecret(config.getOauth().getConsumerSecret())
            .setOAuthAccessToken(config.getOauth().getAccessToken())
            .setOAuthAccessTokenSecret(config.getOauth().getAccessTokenSecret()).setIncludeEntitiesEnabled(true)
            .setJSONStoreEnabled(true).setAsyncNumThreads(3).setRestBaseURL(baseUrl)
            .setIncludeMyRetweetEnabled(Boolean.TRUE).setPrettyDebugEnabled(Boolean.TRUE);

    return new TwitterFactory(builder.build()).getInstance();
}

From source file:org.apache.streams.twitter.provider.TwitterUserInformationProvider.java

License:Apache License

protected Twitter getTwitterClient() {
    String baseUrl = "https://api.twitter.com:443/1.1/";

    ConfigurationBuilder builder = new ConfigurationBuilder()
            .setOAuthConsumerKey(twitterUserInformationConfiguration.getOauth().getConsumerKey())
            .setOAuthConsumerSecret(twitterUserInformationConfiguration.getOauth().getConsumerSecret())
            .setOAuthAccessToken(twitterUserInformationConfiguration.getOauth().getAccessToken())
            .setOAuthAccessTokenSecret(twitterUserInformationConfiguration.getOauth().getAccessTokenSecret())
            .setIncludeEntitiesEnabled(true).setJSONStoreEnabled(true).setAsyncNumThreads(3)
            .setRestBaseURL(baseUrl).setIncludeMyRetweetEnabled(Boolean.TRUE)
            .setPrettyDebugEnabled(Boolean.TRUE);

    return new TwitterFactory(builder.build()).getInstance();
}

From source file:org.apparatus_templi.service.TwitterService.java

License:Open Source License

private void start() {
    accessToken = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccess);
    accessTokenKey = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccessKey);
    if (accessToken != null && accessTokenKey != null) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenKey);
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();/*from   w w w.j av  a  2s  . c  o  m*/
    } else {
        Log.e(TAG, "Twitter service requires authentication for a particular user account.");
    }
}

From source file:org.bireme.interop.toJson.Twitter2Json.java

License:Open Source License

public Twitter2Json(final String userId, final Query query, final int total, final Date lowerDate,
        final boolean useRetweets) throws TwitterException {
    assert ((userId != null) || (query != null));
    assert ((total >= 1) || (lowerDate != null));

    final ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("LmvfpL4pJE7PJr0CgJUuQKZOy")
            .setOAuthConsumerSecret("UP1VIf4K3jGDvOYYXh0zshHnuj8HSUMDTWlJEEhGMWIJHKGXSJ")
            .setOAuthAccessToken("2788081964-9C7j4ZBOsdIy9tmtMkong54QimvjkwopXdLqecm")
            .setOAuthAccessTokenSecret("swwqLPLWppweF3KRKe2zpU9qPNFDbsZm9OqQ5scX9vVCp");

    final Twitter twitter = new TwitterFactory(cb.build()).getInstance();

    this.loader = new TweetLoader(twitter, userId, query, total, lowerDate, useRetweets);
    next = getNext();/*  w  ww . j  ava  2 s  .c o  m*/
}