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:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

/**
 * Method that return the Twitter object that allows the access to the
 * Twitter API//from  www . j a  va 2  s.c  om
 *
 * @param user the user in MeteoCal
 * @return null if there was a problem with the creation of the Twitter
 * object
 */
public static Twitter getTwitterObject(User user) {
    Twitter twitter;

    if (user.getTwitterToken() == null) {
        // Twitter not connected
        return null;
    }

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(CLIENT_ID);
    builder.setOAuthConsumerSecret(CLIENT_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    AccessToken at = new AccessToken(user.getTwitterToken(), user.getTwitterTokenSecret());
    LOGGER.log(Level.INFO, at);
    try {
        twitter.setOAuthAccessToken(at);
    } catch (Exception e) {
        LOGGER.log(Level.ERROR, e);
        return null;
    }
    return twitter;
}

From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

/**
 * Default constructor.//from  w  ww . ja  v  a  2s .c  om
 */
public HandleAuthTwitterImpl() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(CLIENT_ID);
    builder.setOAuthConsumerSecret(CLIENT_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();
    cont = 0;
}

From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java

License:Open Source License

@Override
public String getUrlLoginTwitter() {
    String urlLogin = "error.xhtml";

    try {//from  w  w  w  .  j a  v a  2  s . c  o  m
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(CLIENT_ID);
        builder.setOAuthConsumerSecret(CLIENT_SECRET);
        Configuration configuration = builder.build();
        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();
        //if (requestToken == null) {
        requestToken = twitter.getOAuthRequestToken(URL_BASE + "/MeteoCal-web/loginTwitter.xhtml");
        //}
        urlLogin = requestToken.getAuthenticationURL();
    } catch (TwitterException e) {
        LOGGER.log(Level.ERROR, e);
    }
    cont++;
    LOGGER.log(Level.INFO, "Conteggio: " + cont);
    LOGGER.log(Level.INFO, "URL LOGIN " + urlLogin);
    return urlLogin;
}

From source file:JavaFiles.TwitterAPI.java

public TwitterAPI() {
    cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("53nUEtaL8hsyBS7HyCLZsdj5O")
            .setOAuthConsumerSecret("5ZJ8TeXWj7zHOhK1OtvqxmjD0dIrHUjmtZ7rLOYc9cK0ovDcTF")
            .setOAuthAccessToken("576227678-tDF0uPGF3bjCAFgB7CVRcAXCLWSm7pc7dgEzLVea")
            .setOAuthAccessTokenSecret("LKHdmnEhlTPXkgZrI0jYejrOkhtcJTvf7Gz3kIBCeoFu7");

    tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();/*w  ww  .ja v a2  s .  c  o  m*/
}

From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetMultiple.java

License:Open Source License

private final String init_user_oauth(final int index) {
    oauthToken = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_" + index, ""));
    if (oauthToken.equals("")) {
        WriteLog.write(this, "oauthToken.equals(\"\")");
        final SharedPreferences.Editor editor = pref_twtr.edit();
        editor.putString("index", "0");
        editor.remove("consumer_key_" + index);
        editor.remove("consumer_secret_" + index);
        editor.remove("oauth_token_" + index);
        editor.remove("oauth_token_secret_" + index);
        editor.remove("profile_image_url_" + index);
        editor.remove("screen_name_" + index);
        editor.remove("status_" + index);
        editor.commit();/*from  www  . ja  va  2s .co m*/
    }

    consumerKey = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_key_" + index, ""));
    consumerSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_secret_" + index, ""));
    if (consumerKey.equals("") || consumerSecret.equals("")) {
        WriteLog.write(this, "(consumerKey.equals(\"\") || consumerSecret.equals(\"\"))");
        consumerKey = getString(R.string.default_consumerKey);
        consumerSecret = getString(R.string.default_consumerSecret);
    }

    pref_app = PreferenceManager.getDefaultSharedPreferences(this);
    pref_timeout_t4j_connection = ListAdapter.getPrefInt(this, "pref_timeout_t4j_connection", "20000");
    pref_timeout_t4j_read = ListAdapter.getPrefInt(this, "pref_timeout_t4j_read", "120000");

    oauthTokenSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_secret_" + index, ""));
    try {
        confbuilder = new ConfigurationBuilder();
    } catch (final IllegalStateException e) {
        WriteLog.write(this, e);
    } catch (final Exception e) {
        WriteLog.write(this, e);
    }
    confbuilder.setOAuthAccessToken(oauthToken).setOAuthAccessTokenSecret(oauthTokenSecret)
            .setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
            .setHttpConnectionTimeout(pref_timeout_t4j_connection).setHttpReadTimeout(pref_timeout_t4j_read)
            .setHttpRetryCount(3).setHttpRetryIntervalSeconds(10);// .setUseSSL(true);
    Twitter twtr;
    try {
        conf = confbuilder.build();
        twtr = new TwitterFactory(conf).getInstance();
    } catch (final Exception e) {
        twtr = null;
        WriteLog.write(this, e);
        adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator")
                + getString(R.string.tryagain_oauth));
    }
    WriteLog.write(this, "init_user_oauth(): conf: " + conf.toString());
    WriteLog.write(this, "init_user_oauth(): twtr: " + twtr.toString());

    if (twtr != null) {
        try {
            screenName = twtr.getScreenName();
            User user = twtr.showUser(screenName);
            final String profile_image_url = user.getProfileImageURL().toString();

            pref_twtr = getSharedPreferences("Twitter_setting", MODE_PRIVATE);
            final SharedPreferences.Editor editor = pref_twtr.edit();
            editor.putString("screen_name_" + index, screenName);
            editor.putString("profile_image_url_" + index, profile_image_url);
            editor.commit();

            WriteLog.write(this, "screenName: " + screenName);
            WriteLog.write(this, "profile_image_url: " + profile_image_url);
        } catch (final TwitterException e) {
            WriteLog.write(this, e);
            adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator")
                    + getString(R.string.tryagain_oauth));
        } catch (final Exception e) {
            WriteLog.write(this, e);
            adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator")
                    + getString(R.string.tryagain_oauth));
        }
    }
    return screenName;
}

From source file:jp.xxxxxxxx.l3fish.twnyaan.service.AuthenticationService.java

License:Open Source License

/**
 * RequestToken????URL???????PIN???/*from www  .  java2s  . c o m*/
 * RequestToken??????{@code null}?
 *
 * @return ???RequestToken??????????{@code null}
 */
public RequestToken authorize() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterAPIKey.getConsumerKey())
            .setOAuthConsumerSecret(TwitterAPIKey.getConsumerSecret());
    Twitter twitter = new TwitterFactory(cb.build()).getInstance();

    RequestToken requestToken = null;
    try {
        requestToken = twitter.getOAuthRequestToken();
        URI authorizationURI = new URI(requestToken.getAuthorizationURL());
        Desktop desktop = Desktop.getDesktop();
        desktop.browse(authorizationURI);
    } catch (URISyntaxException | IOException e) {
        System.err.println(ErrorCode.CANNOT_OPEN_AUTHORIZATION_URI);
    } catch (TwitterException e) {
        System.err.println(ErrorCode.TWITTER_SERVICE_UNAVAILABLE);
    }

    return requestToken;
}

From source file:Jums.AllAPI.java

public static Configuration TwitterConnect() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);/*from  w  w  w .j a  v  a2s .  c o m*/
    cb.setOAuthConsumerKey(CONSUMERKEY);
    cb.setOAuthConsumerSecret(CONSUMERSECRET);
    cb.setOAuthAccessToken(TOKEN);
    cb.setOAuthAccessTokenSecret(TOKENSECRET);
    return cb.build();
}

From source file:Jums.SearchTweet.java

public void main(PrintWriter out) {
    try {//w w w . j  a  va  2s.  c  o m
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);
        cb.setOAuthConsumerKey(CONSUMERKEY);
        cb.setOAuthConsumerSecret(CONSUMERSECRET);
        cb.setOAuthAccessToken(TOKEN);
        cb.setOAuthAccessTokenSecret(TOKENSECRET);
        Twitter tw = new TwitterFactory(cb.build()).getInstance();
        User user = tw.verifyCredentials();
        List<Status> statuses = tw.getHomeTimeline();

        for (Status s : statuses) {

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:junit.org.rapidpm.module.iot.twitter.TwitterInitApp.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3")
            .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip")
            .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7")
            .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x");

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/*ww  w  . j av a  2s .c  o m*/

    twitter.getHomeTimeline().forEach(s -> System.out.println("s.getText() = " + s.getText()));

}

From source file:libreriatwitter.Metodos.java

/**
 * Mtodo para acceder a la cuenta con los datos que nos da Twitter Apps
 *//*  w ww .  j  av a 2  s .  co m*/
public Metodos() {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("5zO44Aeo4gLC52fvhqaocpU9P")
            .setOAuthConsumerSecret("0u0YwQrnI5OG4ZpactT4Vyl9eNJbVBdKPhbLOghrCH6sHefcwh")
            .setOAuthAccessToken("182041479-hoD2StntYm3bdCDQFMjueknzKf5YhGIS9OnZNS37")
            .setOAuthAccessTokenSecret("hocHHSwrb0WFbl6g4JI6UdqY9VEUZT3mRqG0ANCU7Jzao");
    twitter = new TwitterFactory(cb.build()).getInstance();
    twitter = new TwitterFactory("twitter4j.properties").getInstance();
}