Example usage for twitter4j TwitterFactory getInstance

List of usage examples for twitter4j TwitterFactory getInstance

Introduction

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

Prototype

public Twitter getInstance() 

Source Link

Document

Returns a instance associated with the configuration bound to this factory.

Usage

From source file:com.fsatir.twitter.TwitterManagedBean.java

public Twitter bringMyTwitterInstance() throws TwitterException {

    String consumerKey = TwitterInfos.CONSUMER_KEY.getCredentialValue();
    String consumerSecret = TwitterInfos.CONSUMER_SECRET.getCredentialValue();
    String oAuthToken = TwitterInfos.OAUTH_TOKEN.getCredentialValue();
    String oAuthSecret = TwitterInfos.OAUTH_SECRET.getCredentialValue();

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    builder.setOAuthAccessToken(oAuthToken);
    builder.setOAuthAccessTokenSecret(oAuthSecret);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();
    return twitter;
}

From source file:com.fuzuapp.model.resultados.TwitterAdapter.java

private void inicializar() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("56dJMai5O3H1MUjUl607LPgOh")
            .setOAuthConsumerSecret("wLsRXEDxDWAgOW217XbSiSK1J2WNG2gqxVDuLIqreI5VYfKEyD")
            .setOAuthAccessToken("64546879-myofEJ5cfPHwaRIud8mSBq2BmM68gHo9gGNgvj8Qb")
            .setOAuthAccessTokenSecret("dzJYWMs4QJUAwOCTisg5eSVLT5xhTp61ecuZ6fNpnARAI");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();

}

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

/**
 * ?/*from w w w. j  a  v  a  2 s . c o  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 {/*  www  .  j av  a2  s  .  c o m*/
        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;//from  w w  w .j a  v a2s.  co 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.illusionaryone.TwitterAPI.java

License:Open Source License

public Boolean authenticate() {
    com.gmt2001.Console.debug.println("Attempting to Authenticate");
    try {/*w ww .java2  s .com*/
        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();
    mResolver = getContentResolver();//from   ww  w  .j ava 2 s .  c  om

}

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

License:Open Source License

public void tweet(String message) {
    TwitterFactory tf = new TwitterFactory(configuration);
    Twitter twitter = tf.getInstance();
    try {//from  www . j a v  a 2  s .c  o  m
        Status status = twitter.updateStatus(message);
        System.out.println("Tweet status: Successfully updated the status to [" + status.getText() + "].");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

License:Open Source License

public void tweet(String message) {
    TwitterFactory tf = new TwitterFactory(configuration);
    Twitter twitter = tf.getInstance();
    try {/*  ww  w  . ja v a 2 s.  co m*/
        Status status = twitter.updateStatus(message);
        Log.d("Tweet status", "Successfully updated the status to [" + status.getText() + "].");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.k42b3.xoxa.TwitterBot.java

License:Open Source License

public TwitterBot(String host, int port, String nick, String pass, String channel, boolean ssl, int minInterval,
        int maxInterval, String consumerKey, String consumerSecret, String accessToken,
        String accessTokenSecret) {
    super(host, port, nick, pass, channel, ssl, minInterval, maxInterval);

    try {/*from   w  ww .ja v  a  2s  .c o m*/
        ConfigurationBuilder cb = new ConfigurationBuilder();

        cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);

        TwitterFactory tf = new TwitterFactory(cb.build());

        this.twitter = tf.getInstance();

        User user = this.twitter.verifyCredentials();

        logger.info("Connected to twitter account " + user.getName());
    } catch (Exception e) {
        logger.warning(e.getMessage());
    }
}