Example usage for twitter4j.conf ConfigurationBuilder build

List of usage examples for twitter4j.conf ConfigurationBuilder build

Introduction

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

Prototype

public Configuration build() 

Source Link

Usage

From source file:com.github.altyjp.webChangeDetector.TweetStrings.java

/**
 * ?/*from  w  ww . j  a  v a 2 s.co  m*/
 *
 * @param str_tweet
 * @throws TwitterException
 */
public void tweetString(String str_tweet) throws TwitterException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(ConsumerKey).setOAuthConsumerSecret(ConsumerSecret)
            .setOAuthAccessToken(AccessToken).setOAuthAccessTokenSecret(AccessTokenSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    //User user = twitter.verifyCredentials();
    //?
    //System.out.println("???" + user.getName());
    //System.out.println("?????" + user.getScreenName());
    //System.err.println("???" + user.getFriendsCount());
    //System.out.println("????" + user.getFollowersCount());
    //??????
    Status status = twitter.updateStatus(str_tweet);
}

From source file:com.github.gorbin.asne.twitter.TwitterSocialNetwork.java

License:Open Source License

private void initTwitterClient() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(fConsumerKey);
    builder.setOAuthConsumerSecret(fConsumerSecret);

    String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null);
    String accessTokenSecret = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_SECRET, null);

    TwitterFactory factory = new TwitterFactory(builder.build());

    if (TextUtils.isEmpty(accessToken) && TextUtils.isEmpty(accessTokenSecret)) {
        mTwitter = factory.getInstance();
    } else {/* w  ww. j a  v a2 s  . c om*/
        mTwitter = factory.getInstance(new AccessToken(accessToken, accessTokenSecret));
    }
}

From source file:com.github.hiro2k.logback.twitter.TwitterAppender.java

License:Apache License

@Override
public void start() {
    boolean requiredPropsSet = true;
    if (getAccessToken() == null) {
        addStatus(new ErrorStatus("Access token not set", this));
        requiredPropsSet = false;/* www  .  j  av  a 2s .c o m*/
    }
    if (getAccessSecret() == null) {
        addStatus(new ErrorStatus("Access secret not set", this));
        requiredPropsSet = false;
    }
    if (getConsumerKey() == null) {
        addStatus(new ErrorStatus("Consumer key not set", this));
        requiredPropsSet = false;
    }
    if (getConsumerSecret() == null) {
        addStatus(new ErrorStatus("Consumer Secret not set", this));
        requiredPropsSet = false;
    }
    if (!requiredPropsSet && twitter == null) {
        addWarn("Appender not started because the required properties weren't all set.");
        return;
    }
    if (layout == null) {
        layout = makeDefaultPatternLayout();
    }
    if (twitter == null) {
        ConfigurationBuilder configBuilder = new ConfigurationBuilder();
        configBuilder.setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret);
        TwitterFactory tf = new TwitterFactory(configBuilder.build());
        this.twitter = tf.getInstance();
    }
    super.start();
}

From source file:com.hortonworks.amuise.cdrstorm.kafka.producers.CDRTestDataProducer.java

private void start() {

    /**/*from www  .j  a  va2 s .c  om*/
     * Kafka Twitter Producer properties *
     */
    Properties twitterconprops = new Properties();
    twitterconprops.put("metadata.broker.list", globalconfigs.getProperty("twitter4j.brokerlist"));
    twitterconprops.put("serializer.class", globalconfigs.getProperty("twitter4j.serializer"));
    twitterconprops.put("request.required.acks", globalconfigs.getProperty("twitter4j.requiredacks"));
    ProducerConfig twitterproducerconfig = new ProducerConfig(twitterconprops);
    final Producer<String, String> twitterproducer = new Producer<String, String>(twitterproducerconfig);

    /**
     * Kafka CDR Producer properties *
     */
    Properties cdrconprops = new Properties();
    cdrconprops.put("metadata.broker.list", globalconfigs.getProperty("cdr.brokerlist"));
    cdrconprops.put("serializer.class", globalconfigs.getProperty("cdr.serializer"));
    cdrconprops.put("request.required.acks", globalconfigs.getProperty("cdr.requiredacks"));
    ProducerConfig cdrproducerconfig = new ProducerConfig(cdrconprops);
    final Producer<String, String> cdrproducer = new Producer<String, String>(cdrproducerconfig);

    /**
     * Twitter4j properties *
     */
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(globalconfigs.getProperty("twitter4j.consumerkey"));
    cb.setOAuthConsumerSecret(globalconfigs.getProperty("twitter4j.consumersecretkey"));
    cb.setOAuthAccessToken(globalconfigs.getProperty("twitter4j.accesstokenkey"));
    cb.setOAuthAccessTokenSecret(globalconfigs.getProperty("twitter4j.accesstokensecretkey"));
    cb.setJSONStoreEnabled(true);
    cb.setIncludeEntitiesEnabled(true);

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

    /**
     * Twitter listener *
     */
    StatusListener listener = new StatusListener() {
        // The onStatus method is executed every time a new tweet comes
        // in.
        public void onStatus(Status status) {

            StringBuilder sb = new StringBuilder();
            sb.append(status.getUser().getScreenName());
            sb.append("|");
            sb.append(status.getCreatedAt());
            sb.append("|");
            sb.append(status.getRetweetCount());
            sb.append("|");
            sb.append(status.getSource());
            sb.append("|");
            sb.append(status.getText());

            //call CDR create message
            String cdrmessage = createCDRMessage(status.getText());

            //Debug output
            System.out.println("_________________________________________________________");
            System.out.println(sb.toString());
            System.out.println("cdr message: " + cdrmessage);
            System.out.println("_________________________________________________________");

            //call producer for tweet
            KeyedMessage<String, String> twitterdata = new KeyedMessage<String, String>(
                    globalconfigs.getProperty("twitter4j.kafkatopic"), sb.toString());
            twitterproducer.send(twitterdata);

            //call producer for cdr
            KeyedMessage<String, String> cdrmessagedata = new KeyedMessage<String, String>(
                    globalconfigs.getProperty("cdr.kafkatopic"), cdrmessage);
            cdrproducer.send(cdrmessagedata);

        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onScrubGeo(long userId, long upToStatusId) {
        }

        public void onException(Exception ex) {
            System.out.println("General Exception: shutting down Twitter sample stream...");
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            twitterStream.shutdown();
        }

        public void onStallWarning(StallWarning warning) {
        }
    };

    twitterStream.addListener(listener);

    // Filter stream with targeted words
    String filterstring = globalconfigs.getProperty("twitter4j.filterwords");
    FilterQuery filterq = new FilterQuery();
    filterq.track(filterstring.split(","));
    twitterStream.filter(filterq);

    //twitterStream.sample();
}

From source file:com.ibuildapp.romanblack.CameraPlugin.SharingActivity.java

License:Open Source License

/**
 * Reinitializes twitter credentials.//from w  w w  .  j a  va 2 s .  co m
 * @return the twitter instance
 */
private Twitter reInitTwitter() {
    com.appbuilder.sdk.android.authorization.entities.User twitterUser = Authorization
            .getAuthorizedUser(Authorization.AUTHORIZATION_TYPE_TWITTER);
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setDebugEnabled(true).setOAuthAccessToken(twitterUser.getAccessToken())
            .setOAuthAccessTokenSecret(twitterUser.getAccessTokenSecret())
            .setOAuthConsumerSecret(Statics.TWITTER_CONSUMER_SECRET)
            .setOAuthConsumerKey(Statics.TWITTER_CONSUMER_KEY);
    Configuration configuration = builder.build();
    return new TwitterFactory(configuration).getInstance();
}

From source file:com.ijuru.tweetgrab.Context.java

License:Open Source License

/**
 * Starts the application/*from w  w  w.j a va 2  s.  c om*/
 * @throws Exception 
 */
public static void startApplication() throws Exception {
    // Look for environment variable or system property
    String optionsJSON = System.getenv(ENVVAR_NAME);
    if (optionsJSON == null) {
        optionsJSON = System.getProperty(JVMPROP_NAME);
        if (optionsJSON == null) {
            throw new Exception("Could not find environment variable (" + ENVVAR_NAME + ") or JVM property ("
                    + JVMPROP_NAME + ")");
        }
    }

    ObjectMapper mapper = new ObjectMapper();
    options = mapper.readValue(optionsJSON, Options.class);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false).setOAuthConsumerKey(options.getCredentials().get("consumerKey"))
            .setOAuthConsumerSecret(options.getCredentials().get("consumerSecret"))
            .setOAuthAccessToken(options.getCredentials().get("accessToken"))
            .setOAuthAccessTokenSecret(options.getCredentials().get("accessTokenSecret"));

    twitterFactory = new TwitterFactory(cb.build());
}

From source file:com.illusionaryone.TwitterAPI.java

License:Open Source License

public Boolean authenticate() {
    com.gmt2001.Console.debug.println("Attempting to Authenticate");
    try {/*from  www  . j a  va  2s. c o m*/
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setOAuthConsumerKey(consumerKey);
        configurationBuilder.setOAuthConsumerSecret(consumerSecret);
        configurationBuilder.setOAuthAccessToken(oauthAccessToken);
        configurationBuilder.setOAuthAccessTokenSecret(oauthAccessSecret);

        TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
        twitter = twitterFactory.getInstance();

        accessToken = twitter.getOAuthAccessToken();
        com.gmt2001.Console.out.println("Authenticated with Twitter API");
        return true;
    } catch (TwitterException ex) {
        com.gmt2001.Console.err.println("Twitter Auth Failed: " + ex.getMessage());
        accessToken = null;
        return false;
    }
}

From source file:com.infine.android.devoxx.service.TwitterService.java

License:Apache License

@Override
public void onCreate() {
    super.onCreate();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("************").setOAuthConsumerSecret("****************")
            .setOAuthAccessToken("***************").setOAuthAccessTokenSecret("**************");
    TwitterFactory tf = new TwitterFactory(cb.build());
    mTwitter = tf.getInstance();//from   ww w  . jav a  2s.c om
    mResolver = getContentResolver();

}

From source file:com.irontec.mintzatu.EzarpenakDetailActivity.java

private void askOAuth() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(TwitterHelper.CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(TwitterHelper.CONSUMER_SECRET);
    Configuration configuration = configurationBuilder.build();
    twitter = new TwitterFactory(configuration).getInstance();

    try {//w  ww  .  ja  v  a2  s  . c o m
        requestToken = twitter.getOAuthRequestToken(TwitterHelper.CALLBACK_URL);
        Intent i = new Intent(this, WebviewActivity.class);
        i.putExtra("URL", requestToken.getAuthenticationURL());
        startActivityForResult(i, TWITTER_AUTH);
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}

From source file:com.isdp.twitterposter.TwitterManager.java

License:Open Source License

public void initTwitter() {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(OAUTH_CONSUMER_KEY)
            .setOAuthConsumerSecret(OAUTH_CONSUMER_SECRET).setOAuthAccessToken(OAUTH_ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(OAUTH_ACCESS_TOKEN_SECRET);
    configuration = configurationBuilder.build();

}