Example usage for twitter4j.conf ConfigurationBuilder setOAuthConsumerSecret

List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerSecret

Introduction

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

Prototype

public ConfigurationBuilder setOAuthConsumerSecret(String oAuthConsumerSecret) 

Source Link

Usage

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public TwitterStream createOneTwitterStreamInstance(AccessToken accessToken) {
    TwitterStream twitterStream;/*from w w  w .  ja  va  2 s  .  c o  m*/
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey());
    builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret());
    System.out.println("AT: " + accessToken.getToken());
    System.out.println("ATS: " + accessToken.getTokenSecret());
    builder.setOAuthAccessToken(accessToken.getToken());
    builder.setOAuthAccessTokenSecret(accessToken.getTokenSecret());
    builder.setJSONStoreEnabled(true);
    //        builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
    //        builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
    Configuration configuration = builder.build();
    TwitterStreamFactory factory = new TwitterStreamFactory(configuration);
    twitterStream = factory.getInstance();

    return twitterStream;
}

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public TwitterStream createOneTwitterStreamInstanceFromApp(String APIKey, String APIKeySecret,
        String accessToken, String accessTokenSecret) {
    TwitterStream twitterStream;//from  w  ww .j a  va2s  .co m
    ConfigurationBuilder builder = new ConfigurationBuilder();
    if (!Admin.isTest()) {
        builder.setOAuthConsumerKey(APIKey);
        builder.setOAuthConsumerSecret(APIKeySecret);
        builder.setOAuthAccessToken(accessToken);
        builder.setOAuthAccessTokenSecret(accessTokenSecret);
        builder.setJSONStoreEnabled(true);
    } else {
        builder.setOAuthConsumerKey("KNjw1QTK1hJKx8LpK6X6rg");
        builder.setOAuthConsumerSecret("ikX9blowuh3FqFAkIg5LQi5voLOV413EWzPsDl77uU");
        builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
        builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
        builder.setJSONStoreEnabled(true);
    }
    Configuration configuration = builder.build();
    TwitterStreamFactory factory = new TwitterStreamFactory(configuration);
    twitterStream = factory.getInstance();

    return twitterStream;
}

From source file:ontoSentiment.Util.java

public static Twitter getTwitter() {
    OAuth2Token token;//from w w  w  . ja  v  a2  s . c o  m
    token = getOAuth2Token();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setApplicationOnlyAuthEnabled(true);
    cb.setOAuthConsumerKey(CONSUMER_KEY);
    cb.setOAuthConsumerSecret(CONSUMER_SECRET);
    cb.setOAuth2TokenType(token.getTokenType());
    cb.setOAuth2AccessToken(token.getAccessToken());
    return new TwitterFactory(cb.build()).getInstance();
}

From source file:org.addhen.smssync.data.twitter.TwitterClient.java

License:Open Source License

private void initTwitterFactory() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(mAuthConfig.consumerKey);
    builder.setOAuthConsumerSecret(mAuthConfig.consumerSecret);
    mTwitterFactory = new TwitterFactory(builder.build());

}

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

License:Apache License

/**
 * Builds a Twitter4J Configuration using the OAuth params.
 *
 * @return Configuration// w w  w. j a  v a 2  s .c om
 */
public Configuration getConfiguration() {
    checkComplete();
    ConfigurationBuilder confBuilder = new ConfigurationBuilder();
    confBuilder.setOAuthConsumerKey(consumerKey);
    confBuilder.setOAuthConsumerSecret(consumerSecret);
    confBuilder.setOAuthAccessToken(accessToken);
    confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
    confBuilder.setUseSSL(useSSL);
    if (getHttpProxyHost() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyHost());
    }
    if (getHttpProxyUser() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyUser());
    }
    if (getHttpProxyPassword() != null) {
        confBuilder.setHttpProxyHost(getHttpProxyPassword());
    }
    if (httpProxyPort != null) {
        confBuilder.setHttpProxyPort(httpProxyPort);
    }

    return confBuilder.build();
}

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;//w  w w .  ja  v a2  s .c  o m

    logConfig();
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

public void connect() throws TwitterException {
    initProperties();/*from   w  w  w  .  ja v a 2  s .c o m*/
    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey(getOauthKey());
    config.setOAuthConsumerSecret(getOauthSecret());
    config.setOAuthAccessToken(getToken());
    config.setOAuthAccessTokenSecret(getTokenSecret());
    twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance();
    User user = twitter.verifyCredentials();
    if (!this.userName.equals(user.getScreenName())) {
        this.userName = user.getScreenName();
        saveProperties(null);
    }
    //AccessToken accessToken = new AccessToken(getToken(), getTokenSecret());
    //twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken);
    //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken);
    //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword());
    setConnection(twitter);
}

From source file:org.fossasia.phimpme.share.twitter.HelperMethods.java

License:Apache License

public static void postToTwitterWithImage(Context context, final String imageUrl, final String message,
        final String token, final String secret, final TwitterCallback postResponse) {
    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
    configurationBuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
    configurationBuilder.setOAuthAccessToken(token);
    configurationBuilder.setOAuthAccessTokenSecret(secret);
    Configuration configuration = configurationBuilder.build();
    final Twitter twitter = new TwitterFactory(configuration).getInstance();

    final File file = new File(imageUrl);
    boolean success = true;
    if (file.exists()) {
        try {/*  w w w . ja  va 2  s.  c  o m*/
            StatusUpdate status = new StatusUpdate(message);
            status.setMedia(file);
            twitter.updateStatus(status);
        } catch (TwitterException e) {
            e.printStackTrace();
            success = false;
        }
    } else {
        Log.d(TAG, "----- Invalid File ----------");
        success = false;
    }
    postResponse.onFinsihed(success);

}

From source file:org.fossasia.phimpme.share.twitter.LoginActivity.java

License:Apache License

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

    new Thread(new Runnable() {
        @Override//from w w w. ja  va 2s.c o  m
        public void run() {
            try {
                requestToken = twitter.getOAuthRequestToken(AppConstant.TWITTER_CALLBACK_URL);
            } catch (Exception e) {
                final String errorString = e.toString();
                LoginActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dialog.dismiss();
                        SnackBarHandler.show(parentView, errorString);
                        finish();
                    }
                });
                return;
            }

            LoginActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    twitterLoginWebView.loadUrl(requestToken.getAuthenticationURL());
                }
            });
        }
    }).start();
}

From source file:org.getlantern.firetweet.activity.support.SignInActivity.java

License:Open Source License

private Configuration getConfiguration() {
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    final boolean enable_gzip_compressing = mPreferences.getBoolean(KEY_GZIP_COMPRESSING, false);
    final boolean ignore_ssl_error = mPreferences.getBoolean(KEY_IGNORE_SSL_ERROR, false);
    final boolean enable_proxy = mPreferences.getBoolean(KEY_ENABLE_PROXY, false);
    cb.setHostAddressResolverFactory(new FiretweetHostResolverFactory(mApplication));
    cb.setHttpClientFactory(new OkHttpClientFactory(mApplication));
    if (TwitterContentUtils.isOfficialKey(this, mConsumerKey, mConsumerSecret)) {
        Utils.setMockOfficialUserAgent(this, cb);
    } else {/* w  ww .  j ava  2s  .  c  om*/
        Utils.setUserAgent(this, cb);
    }
    final String apiUrlFormat = TextUtils.isEmpty(mAPIUrlFormat) ? DEFAULT_TWITTER_API_URL_FORMAT
            : mAPIUrlFormat;
    final String versionSuffix = mNoVersionSuffix ? null : "/1.1/";
    cb.setRestBaseURL(Utils.getApiUrl(apiUrlFormat, "api", versionSuffix));
    cb.setOAuthBaseURL(Utils.getApiUrl(apiUrlFormat, "api", "/oauth/"));
    cb.setUploadBaseURL(Utils.getApiUrl(apiUrlFormat, "upload", versionSuffix));
    cb.setOAuthAuthorizationURL(Utils.getApiUrl(apiUrlFormat, null, "/oauth/authorize"));
    cb.setHttpUserAgent(Utils.generateBrowserUserAgent());
    if (!mSameOAuthSigningUrl) {
        cb.setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL);
        cb.setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL);
        cb.setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL);
    }
    if (isEmpty(mConsumerKey) || isEmpty(mConsumerSecret)) {
        cb.setOAuthConsumerKey(TWITTER_CONSUMER_KEY_3);
        cb.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET_3);
    } else {
        cb.setOAuthConsumerKey(mConsumerKey);
        cb.setOAuthConsumerSecret(mConsumerSecret);
    }
    cb.setGZIPEnabled(enable_gzip_compressing);
    cb.setIgnoreSSLError(ignore_ssl_error);
    if (enable_proxy) {
        final String proxy_host = mPreferences.getString(KEY_PROXY_HOST, null);
        final int proxy_port = ParseUtils.parseInt(mPreferences.getString(KEY_PROXY_PORT, "-1"));
        if (!isEmpty(proxy_host) && proxy_port > 0) {
            cb.setHttpProxyHost(proxy_host);
            cb.setHttpProxyPort(proxy_port);
        }
    }
    return cb.build();
}