List of usage examples for twitter4j.conf ConfigurationBuilder setHttpProxyPort
public ConfigurationBuilder setHttpProxyPort(int httpProxyPort)
From source file:org.apache.camel.component.twitter.TwitterConfiguration.java
License:Apache License
/** * Builds a Twitter4J Configuration using the OAuth params. * * @return Configuration//from ww w.jav a 2s . c o m */ 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.bonitasoft.connectors.twitter.TwitterConnector.java
License:Open Source License
@Override protected void executeConnector() throws Exception { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); if (getProxyHost() != null && getProxyPort() != null) { configurationBuilder.setHttpProxyHost(getProxyHost()); configurationBuilder.setHttpProxyPort(getProxyPort()); if (getProxyUser() != null && getProxyPass() != null) { configurationBuilder.setHttpProxyUser(getProxyUser()); configurationBuilder.setHttpProxyPassword(getProxyPass()); }//from w ww . j a v a2 s . co m } Configuration configuration = new ConfigurationBuilder().build(); AccessToken token = new AccessToken(accessToken, accessTokenSecret); OAuthAuthorization authorization = new OAuthAuthorization(configuration, consumerKey, consumerSecret, token); Twitter twitter = new TwitterFactory().getInstance(authorization); executeTask(twitter); }
From source file:org.elasticsearch.river.twitter.TwitterRiver.java
License:Apache License
/** * Twitter Stream Builder//from ww w. j a v a 2 s . c o m * @return */ private TwitterStream buildTwitterStream() { logger.debug("creating TwitterStreamFactory"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(oauthConsumerKey).setOAuthConsumerSecret(oauthConsumerSecret) .setOAuthAccessToken(oauthAccessToken).setOAuthAccessTokenSecret(oauthAccessTokenSecret); if (proxyHost != null) cb.setHttpProxyHost(proxyHost); if (proxyPort != null) cb.setHttpProxyPort(Integer.parseInt(proxyPort)); if (proxyUser != null) cb.setHttpProxyUser(proxyUser); if (proxyPassword != null) cb.setHttpProxyPassword(proxyPassword); if (raw) cb.setJSONStoreEnabled(true); // We force SSL usage cb.setUseSSL(true); TwitterStream stream = new TwitterStreamFactory(cb.build()).getInstance(); stream.addListener(new StatusHandler()); return stream; }
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 {//from w w w . j av a2 s. 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(); }
From source file:org.getlantern.firetweet.util.Utils.java
License:Open Source License
public static HttpClientWrapper getHttpClient(final Context context, final int timeoutMillis, final boolean ignoreSslError, final Proxy proxy, final HostAddressResolverFactory resolverFactory, final String userAgent, final boolean twitterClientHeader) { final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setHttpConnectionTimeout(timeoutMillis); cb.setIgnoreSSLError(ignoreSslError); cb.setIncludeTwitterClientHeader(twitterClientHeader); if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) { final SocketAddress address = proxy.address(); if (address instanceof InetSocketAddress) { cb.setHttpProxyHost(((InetSocketAddress) address).getHostName()); cb.setHttpProxyPort(((InetSocketAddress) address).getPort()); }/*from w w w . j av a2s . c o m*/ } cb.setHostAddressResolverFactory(resolverFactory); if (userAgent != null) { cb.setHttpUserAgent(userAgent); } cb.setHttpClientFactory(new OkHttpClientFactory(context)); return new HttpClientWrapper(cb.build()); }
From source file:org.getlantern.firetweet.util.Utils.java
License:Open Source License
@Nullable public static Twitter getTwitterInstance(final Context context, final long accountId, final boolean includeEntities, final boolean includeRetweets) { if (context == null) return null; final FiretweetApplication app = FiretweetApplication.getInstance(context); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int connection_timeout = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10) * 1000; final boolean enableGzip = prefs.getBoolean(KEY_GZIP_COMPRESSING, true); final boolean ignoreSslError = prefs.getBoolean(KEY_IGNORE_SSL_ERROR, false); final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false); // Here I use old consumer key/secret because it's default key for older // versions//from ww w . ja v a 2 s . c om final ParcelableCredentials credentials = ParcelableCredentials.getCredentials(context, accountId); if (credentials == null) return null; final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setHostAddressResolverFactory(new FiretweetHostResolverFactory(app)); cb.setHttpClientFactory(new OkHttpClientFactory(context)); cb.setHttpConnectionTimeout(connection_timeout); cb.setGZIPEnabled(enableGzip); cb.setIgnoreSSLError(ignoreSslError); cb.setIncludeCards(true); cb.setCardsPlatform("Android-12"); // cb.setModelVersion(7); if (enableProxy) { final String proxy_host = prefs.getString(KEY_PROXY_HOST, null); final int proxy_port = ParseUtils.parseInt(prefs.getString(KEY_PROXY_PORT, "-1")); if (!isEmpty(proxy_host) && proxy_port > 0) { cb.setHttpProxyHost(proxy_host); cb.setHttpProxyPort(proxy_port); } } final String prefConsumerKey = prefs.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY); final String prefConsumerSecret = prefs.getString(KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET); final String apiUrlFormat = credentials.api_url_format; final String consumerKey = trim(credentials.consumer_key); final String consumerSecret = trim(credentials.consumer_secret); final boolean sameOAuthSigningUrl = credentials.same_oauth_signing_url; final boolean noVersionSuffix = credentials.no_version_suffix; if (!isEmpty(apiUrlFormat)) { final String versionSuffix = noVersionSuffix ? null : "/1.1/"; cb.setRestBaseURL(getApiUrl(apiUrlFormat, "api", versionSuffix)); cb.setOAuthBaseURL(getApiUrl(apiUrlFormat, "api", "/oauth/")); cb.setUploadBaseURL(getApiUrl(apiUrlFormat, "upload", versionSuffix)); cb.setOAuthAuthorizationURL(getApiUrl(apiUrlFormat, null, null)); if (!sameOAuthSigningUrl) { cb.setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL); cb.setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL); cb.setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL); } } if (TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret)) { setMockOfficialUserAgent(context, cb); } else { setUserAgent(context, cb); } cb.setIncludeEntitiesEnabled(includeEntities); cb.setIncludeRTsEnabled(includeRetweets); cb.setIncludeReplyCountEnabled(true); cb.setIncludeDescendentReplyCountEnabled(true); switch (credentials.auth_type) { case Accounts.AUTH_TYPE_OAUTH: case Accounts.AUTH_TYPE_XAUTH: { if (!isEmpty(consumerKey) && !isEmpty(consumerSecret)) { cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); } else if (!isEmpty(prefConsumerKey) && !isEmpty(prefConsumerSecret)) { cb.setOAuthConsumerKey(prefConsumerKey); cb.setOAuthConsumerSecret(prefConsumerSecret); } else { cb.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); cb.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); } final String token = credentials.oauth_token; final String tokenSecret = credentials.oauth_token_secret; if (isEmpty(token) || isEmpty(tokenSecret)) return null; return new TwitterFactory(cb.build()).getInstance(new AccessToken(token, tokenSecret)); } case Accounts.AUTH_TYPE_BASIC: { final String screenName = credentials.screen_name; final String username = credentials.basic_auth_username; final String loginName = username != null ? username : screenName; final String password = credentials.basic_auth_password; if (isEmpty(loginName) || isEmpty(password)) return null; return new TwitterFactory(cb.build()).getInstance(new BasicAuthorization(loginName, password)); } case Accounts.AUTH_TYPE_TWIP_O_MODE: { return new TwitterFactory(cb.build()).getInstance(new TwipOModeAuthorization()); } default: { return null; } } }
From source file:org.loklak.scraper.TwitterRiver.java
License:Apache License
/** * Build configuration object with credentials and proxy settings * @return/*from w w w . j a v a 2s . c om*/ */ private Configuration buildTwitterConfiguration() { logger.debug("creating twitter configuration"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(oauthConsumerKey).setOAuthConsumerSecret(oauthConsumerSecret) .setOAuthAccessToken(oauthAccessToken).setOAuthAccessTokenSecret(oauthAccessTokenSecret); if (proxyHost != null) cb.setHttpProxyHost(proxyHost); if (proxyPort != null) cb.setHttpProxyPort(Integer.parseInt(proxyPort)); if (proxyUser != null) cb.setHttpProxyUser(proxyUser); if (proxyPassword != null) cb.setHttpProxyPassword(proxyPassword); if (raw) cb.setJSONStoreEnabled(true); logger.debug("twitter configuration created"); return cb.build(); }
From source file:org.mariotaku.twidere.activity.SignInActivity.java
License:Open Source License
private Configuration getConfiguration() { final ConfigurationBuilder cb = new ConfigurationBuilder(); final boolean enable_gzip_compressing = mPreferences.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, false); final boolean ignore_ssl_error = mPreferences.getBoolean(PREFERENCE_KEY_IGNORE_SSL_ERROR, false); final boolean enable_proxy = mPreferences.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false); final String consumer_key = mPreferences.getString(PREFERENCE_KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY) .trim();// w ww. java 2 s . c om final String consumer_secret = mPreferences .getString(PREFERENCE_KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET).trim(); cb.setHostAddressResolver(mApplication.getHostAddressResolver()); if (mPassword == null || !mPassword.contains("*")) { cb.setHttpClientImplementation(HttpClientImpl.class); } setUserAgent(this, cb); if (!isEmpty(mRESTBaseURL)) { cb.setRestBaseURL(mRESTBaseURL); } if (!isEmpty(mOAuthBaseURL)) { cb.setOAuthBaseURL(mOAuthBaseURL); } if (!isEmpty(mSigningRESTBaseURL)) { cb.setSigningRestBaseURL(mSigningRESTBaseURL); } if (!isEmpty(mSigningOAuthBaseURL)) { cb.setSigningOAuthBaseURL(mSigningOAuthBaseURL); } if (isEmpty(consumer_key) || isEmpty(consumer_secret)) { cb.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); cb.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); } else { cb.setOAuthConsumerKey(consumer_key); cb.setOAuthConsumerSecret(consumer_secret); } cb.setGZIPEnabled(enable_gzip_compressing); cb.setIgnoreSSLError(ignore_ssl_error); if (enable_proxy) { final String proxy_host = mPreferences.getString(PREFERENCE_KEY_PROXY_HOST, null); final int proxy_port = ParseUtils.parseInt(mPreferences.getString(PREFERENCE_KEY_PROXY_PORT, "-1")); if (!isEmpty(proxy_host) && proxy_port > 0) { cb.setHttpProxyHost(proxy_host); cb.setHttpProxyPort(proxy_port); } } return cb.build(); }
From source file:org.mariotaku.twidere.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 TwidereHostResolverFactory(mApplication)); cb.setHttpClientFactory(new OkHttpClientFactory(mApplication)); Utils.setClientUserAgent(this, mConsumerKey, mConsumerSecret, cb); final String apiUrlFormat = TextUtils.isEmpty(mAPIUrlFormat) ? DEFAULT_TWITTER_API_URL_FORMAT : mAPIUrlFormat;/*from w ww . j a va2 s . c o m*/ 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")); 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(); }
From source file:org.mariotaku.twidere.activity.TwitterLoginActivity.java
License:Open Source License
private ConfigurationBuilder setAPI(ConfigurationBuilder cb) { final SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final boolean enable_gzip_compressing = preferences.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, false); final boolean ignore_ssl_error = preferences.getBoolean(PREFERENCE_KEY_IGNORE_SSL_ERROR, false); final boolean enable_proxy = preferences.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false); final String consumer_key = preferences.getString(PREFERENCE_KEY_CONSUMER_KEY, CONSUMER_KEY); final String consumer_secret = preferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, CONSUMER_SECRET); if (!isNullOrEmpty(mRestBaseURL)) { cb.setRestBaseURL(mRestBaseURL); }//from w w w . j a v a 2s .c o m if (!isNullOrEmpty(mSearchBaseURL)) { cb.setSearchBaseURL(mSearchBaseURL); } if (!isNullOrEmpty(mUploadBaseURL)) { cb.setUploadBaseURL(mUploadBaseURL); } if (!isNullOrEmpty(mSigningRESTBaseURL)) { cb.setSigningRestBaseURL(mSigningRESTBaseURL); } if (!isNullOrEmpty(mOAuthBaseURL)) { cb.setOAuthBaseURL(mOAuthBaseURL); } if (!isNullOrEmpty(mSigningOAuthBaseURL)) { cb.setSigningOAuthBaseURL(mSigningOAuthBaseURL); } if (isNullOrEmpty(consumer_key) || isNullOrEmpty(consumer_secret)) { cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); } else { cb.setOAuthConsumerKey(consumer_key); cb.setOAuthConsumerSecret(consumer_secret); } cb.setGZIPEnabled(enable_gzip_compressing); cb.setIgnoreSSLError(ignore_ssl_error); if (enable_proxy) { final String proxy_host = preferences.getString(PREFERENCE_KEY_PROXY_HOST, null); final int proxy_port = parseInt(preferences.getString(PREFERENCE_KEY_PROXY_PORT, "-1")); if (isNullOrEmpty(proxy_host) && proxy_port > 0) { cb.setHttpProxyHost(proxy_host); cb.setHttpProxyPort(proxy_port); } } return cb; }