Example usage for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey

Introduction

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

Prototype

public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey) 

Source Link

Usage

From source file:com.reyk.socialmedia.implementations.TwitterSB.java

@Override
public void postComment(String username, String post) throws EJBException {
    try {// w  ww  . j a v  a 2s. c o  m
        String fileName = "twitter-" + username + ".properties";
        File file = new File(fileName);
        OutputStream outputStream = null;
        Properties prop = new Properties();
        InputStream inputStream = null;

        try {
            if (file.exists()) {
                inputStream = new FileInputStream(file);
                prop.load(inputStream);
            } else {
                throw new EJBException("There is no configuration int Twitter for " + username);
            }

        } catch (IOException ioEx) {
            ioEx.printStackTrace();
            System.exit(-1);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException ignore) {
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException ignore) {
                }
            }
        }
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setOAuthConsumerKey("a7QcplYaabjAy7Qw6WsyNAkwy")
                .setOAuthConsumerSecret("1xHSPlDU6eUp7YkkZL9oQioeQGuKiZHtwNuUCmTbARD2MoJLwV")
                .setOAuthAccessToken(prop.getProperty("oauth.accessToken"))
                .setOAuthAccessTokenSecret(prop.getProperty("oauth.accessTokenSecret"));
        twitter = new TwitterFactory(cb.build()).getInstance();
        twitter.updateStatus(post);
    } catch (TwitterException e) {
        throw new EJBException("Error en el twitter sb al twittear", e);
    }
}

From source file:com.rowland.hashtrace.utility.Utility.java

License:Apache License

public static Twitter getTwitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(Constants.TWITTER_CONSUMER_KEY);
    cb.setOAuthConsumerSecret(Constants.TWITTER_CONSUMER_SECRET);
    cb.setOAuthAccessToken(Constants.TWITTER_ACCESS_TOKEN);
    cb.setOAuthAccessTokenSecret(Constants.TWITTER_TOKEN_SECRET).setHttpConnectionTimeout(100000);
    //cb.setUseSSL(true);

    /*/*from w ww.j ava 2s .c om*/
     * if() { cb.setHttpProxyHost(httpProxyHost);
     * cb.setHttpProxyPort(httpProxyPort);
     * cb.setHttpProxyUser(httpProxyUser);
     * cb.setHttpProxyPassword(httpProxyPassword);
     *
     * }
     */

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

From source file:com.sinfonier.drains.TweetIt.java

License:Apache License

@Override
public void userexecute() {

    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey(this.CONSUMER_KEY);
    config.setOAuthConsumerSecret(this.CONSUMER_SECRET);
    config.setOAuthAccessToken(this.ACCESS_TOKEN);
    config.setOAuthAccessTokenSecret(this.ACCESS_TOKEN_SECRET);
    config.setJSONStoreEnabled(true);//www .  j  a  v  a  2s.  c  o  m
    config.setIncludeEntitiesEnabled(true);
    try {
        TwitterFactory tf = new TwitterFactory(config.build());
        Twitter twitter = tf.getInstance();
        Status status = twitter.updateStatus(this.customText + " " + this.getField(this.fieldToTweet));
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
    } catch (TwitterException te) {
        te.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.sinfonier.spouts.Twitter.java

License:Apache License

/**
 * Create a TwitterStream. Requires Twitter API keys.
 * /*  ww  w  .java 2  s  . com*/
 * @return {@link twitter4j.TwitterStream}
 */
private TwitterStream createTwitterStream() {

    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey(xml.get(CONSUMER_KEY, true));
    config.setOAuthConsumerSecret(xml.get(CONSUMER_SECRET, true));
    config.setOAuthAccessToken(xml.get(ACCESS_TOKEN, true));
    config.setOAuthAccessTokenSecret(xml.get(ACCESS_TOKEN_SECRET, true));
    config.setJSONStoreEnabled(true);
    config.setIncludeEntitiesEnabled(true);

    return new TwitterStreamFactory(config.build()).getInstance();
}

From source file:com.socialnetwork.abhishekchandale.snloginlib.twitter.TwitterSocialNetwork.java

License:Open Source License

private void initTwitterClient() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(mConsumerKey);
    builder.setOAuthConsumerSecret(mConsumerSecret);

    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  w  w  .  j av  a2  s. com
        mTwitter = factory.getInstance(new twitter4j.auth.AccessToken(accessToken, accessTokenSecret));
    }
}

From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java

License:Apache License

/**
 * {@inheritDoc}//from   ww  w  .ja  va  2s . co m
 */
@Override
public void configure(Map<String, String> providerParams) {
    autoLogin = false;

    if (providerParams != null) {
        twitterConsumerKey = providerParams.get("consumerKey");
        twitterConsumerSecret = providerParams.get("consumerSecret");

        // extract autoLogin
        String autoLoginStr = providerParams.get("autoLogin");
        autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr);
    }

    SoomlaUtils.LogDebug(TAG,
            String.format("ConsumerKey:%s ConsumerSecret:%s", twitterConsumerKey, twitterConsumerSecret));

    if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) {
        SoomlaUtils.LogError(TAG,
                "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters");
        isInitialized = false;
    } else {
        isInitialized = true;
    }

    oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey;

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(twitterConsumerKey);
    configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret);
    Configuration configuration = configurationBuilder.build();
    twitter = new AsyncTwitterFactory(configuration).getInstance();

    if (!actionsListenerAdded) {
        SoomlaUtils.LogWarning(TAG, "added action listener");
        twitter.addListener(actionsListener);
        actionsListenerAdded = true;
    }
}

From source file:com.speed.traquer.app.TraqComplaintTaxi.java

/**
 * Function to login twitter/* w w w  .  j  a  va  2 s .c o m*/
 * */

private void loginToTwitter() {

    // Check if already logged in
    if (!isTwitterLoggedInAlready()) {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
        Configuration configuration = builder.build();

        TwitterFactory factory = new TwitterFactory(configuration);
        twitter = factory.getInstance();

        try {
            requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    } else {
        // user already logged into twitter
        Toast.makeText(TraqComplaintTaxi.this, "Already Logged into twitter", Toast.LENGTH_SHORT).show();

        /* Get Access Token after login*/
        /*try {
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
                
        // Access Token
        String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
        // Access Token Secret
        String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");
                
        AccessToken accessToken = new AccessToken(access_token, access_token_secret);
        Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
                
                
        // Getting user details from twitter
        // For now i am getting his name only
        twitterID= accessToken.getUserId();
        User user = twitter.showUser(twitterID);
                
        userName = user.getName();
                
        // Displaying in xml ui
        //lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>" + description));
                
                
        } catch (TwitterException e) {
        // Error in updating status
        Log.d("Twitter Update Error", e.getMessage());
        }*/

    }
}

From source file:com.speed.traquer.app.TraqComplaintTaxi.java

private void checkTwitterID() {

    /* Get Access Token after login*/
    try {//  w ww  . j av a  2s  . c om
        ConfigurationBuilder builder = new ConfigurationBuilder();
        builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
        builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);

        // Access Token
        String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
        // Access Token Secret
        String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

        AccessToken accessToken = new AccessToken(access_token, access_token_secret);
        Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

        // Getting user details from twitter
        // For now i am getting his name only
        twitterID = accessToken.getUserId();
        User user = twitter.showUser(twitterID);

        userName = user.getName();

        //Toast.makeText(TraqComplaintTaxi.this, Long.toString(twitterID) + userName, Toast.LENGTH_SHORT).show();
        // Displaying in xml ui
        //lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>" + description));

    } catch (TwitterException e) {
        // Error in updating status
        Log.d("Twitter Update Error", e.getMessage());
    } catch (Exception e) {
        // Error in updating status
        Log.d("error!", e.getMessage());
    }
}

From source file:com.telefonica.iot.cygnus.sources.TwitterSource.java

License:Open Source License

@Override
public void configure(Context context) {
    consumerKey = context.getString("consumerKey");
    consumerSecret = context.getString("consumerSecret");
    accessToken = context.getString("accessToken");
    accessTokenSecret = context.getString("accessTokenSecret");

    LOGGER.info("Consumer Key:        '" + consumerKey + "'");
    LOGGER.info("Consumer Secret:     '" + consumerSecret + "'");
    LOGGER.info("Access Token:        '" + accessToken + "'");
    LOGGER.info("Access Token Secret: '" + accessTokenSecret + "'");

    String southWestLatitude;/*from   w ww .  j  av  a2s .co m*/
    String southWestLongitude;
    String northEastLatitude;
    String northEastLongitude;
    String keywords;

    //Top-left coordinate
    southWestLatitude = context.getString("south_west_latitude");
    southWestLongitude = context.getString("south_west_longitude");
    LOGGER.info("South-West coordinate: '" + southWestLatitude + " " + southWestLongitude + "'");

    //Bottom-right coordinate
    northEastLatitude = context.getString("north_east_latitude");
    northEastLongitude = context.getString("north_east_longitude");
    LOGGER.info("North-East coordinate: '" + northEastLatitude + " " + northEastLongitude + "'");

    keywords = context.getString("keywords");
    LOGGER.info("Keywords:            '" + keywords + "'");

    if (southWestLatitude != null && southWestLongitude != null && northEastLatitude != null
            && northEastLongitude != null) {
        double latitude1 = Double.parseDouble(southWestLatitude);
        double longitude1 = Double.parseDouble(southWestLongitude);

        double latitude2 = Double.parseDouble(northEastLatitude);
        double longitude2 = Double.parseDouble(northEastLongitude);

        boundingBox = new double[][] { new double[] { longitude1, latitude1 }, // south-west
                new double[] { longitude2, latitude2 } // north-east
        };

        LOGGER.info("Coordinates:         '" + boundingBox[0][0] + " " + boundingBox[0][1] + " "
                + boundingBox[1][0] + " " + boundingBox[1][1] + "'");
        haveFilters = true;
        haveCoordinateFilter = true;
    }

    if (keywords != null) {
        if (keywords.trim().length() != 0) {
            splitKeywords = keywords.split(",");
            for (int i = 0; i < splitKeywords.length; i++) {
                splitKeywords[i] = splitKeywords[i].trim();
            }

            LOGGER.info("keywords:            {}", Arrays.toString(splitKeywords));
            haveFilters = true;
            haveKeywordFilter = true;
        }
    }

    maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
    maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis", maxBatchDurationMillis);

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(consumerKey);
    cb.setOAuthConsumerSecret(consumerSecret);
    cb.setOAuthAccessToken(accessToken);
    cb.setOAuthAccessTokenSecret(accessTokenSecret);
    cb.setJSONStoreEnabled(true);

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

}

From source file:com.tweet.HelperMethods.java

License:Apache License

public static void postToTwitter(Context context, final Activity callingActivity, final String message,
        final TwitterCallback postResponse) {
    if (!LoginActivity.isActive(context)) {
        postResponse.onFinsihed(false);/*www  .j av  a 2  s . c om*/
        return;
    }

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key));
    configurationBuilder
            .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret));
    configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken((context)));
    configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context));
    Configuration configuration = configurationBuilder.build();
    final Twitter twitter = new TwitterFactory(configuration).getInstance();

    new Thread(new Runnable() {

        @Override
        public void run() {
            boolean success = true;
            try {
                Calendar cal = Calendar.getInstance();

                twitter.updateStatus(message + "\n@" + cal.getTime().toString());
            } catch (TwitterException e) {
                e.printStackTrace();
                success = false;
            }

            final boolean finalSuccess = success;

            callingActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    postResponse.onFinsihed(finalSuccess);
                }
            });

        }
    }).start();
}