List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerSecret
public ConfigurationBuilder setOAuthConsumerSecret(String oAuthConsumerSecret)
From source file:com.pulzitinc.flume.source.TwitterSource.java
License:Apache License
/** * The initialization method for the Source. The context contains all the * Flume configuration info, and can be used to retrieve any configuration * values necessary to set up the Source. *//*from w w w. j ava2s .c o m*/ @Override public void configure(Context context) { logger.info(context.toString()); consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY); consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY); accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY); accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY); String accountIdsString = context.getString(TwitterSourceConstants.ACCOUNT_IDS_KEY, ""); if (accountIdsString.trim().length() == 0) { throw new IllegalStateException("No accounts to follow provided"); } else { String[] accountIds = accountIdsString.split(","); accountsToFollow = new long[accountIds.length]; for (int i = 0; i < accountIds.length; i++) { accountsToFollow[i] = Long.valueOf(accountIds[i]); } } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); }
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 w w.j av a 2 s . c o m * 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);/*from w ww. j a va2 s . com*/ 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. * /*from w w w . ja v a2 s. c o m*/ * @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. ja va 2 s . co m*/ mTwitter = factory.getInstance(new twitter4j.auth.AccessToken(accessToken, accessTokenSecret)); } }
From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java
License:Apache License
/** * {@inheritDoc}/* w ww .j a va 2 s.c o 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// ww w . j a v a 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 {/*from ww w. j a v a 2 s. 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 ww w . ja va2s . c o 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);/* w w w. jav a 2 s . c o m*/ 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(); }