Example usage for twitter4j TwitterFactory TwitterFactory

List of usage examples for twitter4j TwitterFactory TwitterFactory

Introduction

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

Prototype

public TwitterFactory(String configTreePath) 

Source Link

Document

Creates a TwitterFactory with a specified config tree

Usage

From source file:org.apache.blur.demo.twitter.TwitterSearchQueueReader.java

License:Apache License

public TwitterSearchQueueReader(BlurIndex index, ShardContext shardContext) {
    super(index, shardContext);
    twitter = new TwitterFactory(new ConfigurationBuilder().build()).getInstance();

    try {/*from   w w w.jav a2 s . c o  m*/
        OAuth2Token token = twitter.getOAuth2Token();
    } catch (TwitterException e) {
        throw new RuntimeException("Unable to connect to twitter.", e);
    }
    searchCriteria = _tableContext.getDescriptor().getTableProperties().get(TWITTER_SEARCH_CRITERIA_KEY);
    tableName = _tableContext.getTable();

    if (searchCriteria == null) {
        throw new RuntimeException("Twitter search criteria cannot be null.");
    }
    log.info("Initialized with search criteria[" + searchCriteria + "]");
}

From source file:org.apache.blur.demo.twitter.Whiteboard.java

License:Apache License

/**
 * @param args/*from  w  w w.  j  a  v a 2  s.c  om*/
 * @throws TwitterException
 */
public static void main(String[] args) throws TwitterException {
    Twitter twitter = new TwitterFactory(new ConfigurationBuilder().build()).getInstance();
    OAuth2Token token = twitter.getOAuth2Token();
    System.out.println(token.getTokenType());

    try {
        Query query = new Query("Apache");
        QueryResult result;
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            for (Status tweet : tweets) {
                System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());

            }
        } 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);
    }

}

From source file:org.apache.camel.component.twitter.TwitterConfiguration.java

License:Apache License

public Twitter getTwitter() {
    if (twitter == null) {
        twitter = new TwitterFactory(getConfiguration()).getInstance();
    }
    return twitter;
}

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  ww w. j a va2 s .c om
}

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;/*from   w w w.  j av  a  2s  .c  om*/

    logConfig();
}

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();
    }// w  ww.j  a  va  2s  .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 www.  j  av  a2  s.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();/*from www.  j av a 2s  .  co  m*/
}