List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessTokenSecret
public ConfigurationBuilder setOAuthAccessTokenSecret(String oAuthAccessTokenSecret)
From source file:com.hortonworks.amuise.cdrstorm.kafka.producers.CDRTestDataProducer.java
private void start() { /**//w w w .j av a 2 s.co m * Kafka Twitter Producer properties * */ Properties twitterconprops = new Properties(); twitterconprops.put("metadata.broker.list", globalconfigs.getProperty("twitter4j.brokerlist")); twitterconprops.put("serializer.class", globalconfigs.getProperty("twitter4j.serializer")); twitterconprops.put("request.required.acks", globalconfigs.getProperty("twitter4j.requiredacks")); ProducerConfig twitterproducerconfig = new ProducerConfig(twitterconprops); final Producer<String, String> twitterproducer = new Producer<String, String>(twitterproducerconfig); /** * Kafka CDR Producer properties * */ Properties cdrconprops = new Properties(); cdrconprops.put("metadata.broker.list", globalconfigs.getProperty("cdr.brokerlist")); cdrconprops.put("serializer.class", globalconfigs.getProperty("cdr.serializer")); cdrconprops.put("request.required.acks", globalconfigs.getProperty("cdr.requiredacks")); ProducerConfig cdrproducerconfig = new ProducerConfig(cdrconprops); final Producer<String, String> cdrproducer = new Producer<String, String>(cdrproducerconfig); /** * Twitter4j properties * */ ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(globalconfigs.getProperty("twitter4j.consumerkey")); cb.setOAuthConsumerSecret(globalconfigs.getProperty("twitter4j.consumersecretkey")); cb.setOAuthAccessToken(globalconfigs.getProperty("twitter4j.accesstokenkey")); cb.setOAuthAccessTokenSecret(globalconfigs.getProperty("twitter4j.accesstokensecretkey")); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); /** * Twitter listener * */ StatusListener listener = new StatusListener() { // The onStatus method is executed every time a new tweet comes // in. public void onStatus(Status status) { StringBuilder sb = new StringBuilder(); sb.append(status.getUser().getScreenName()); sb.append("|"); sb.append(status.getCreatedAt()); sb.append("|"); sb.append(status.getRetweetCount()); sb.append("|"); sb.append(status.getSource()); sb.append("|"); sb.append(status.getText()); //call CDR create message String cdrmessage = createCDRMessage(status.getText()); //Debug output System.out.println("_________________________________________________________"); System.out.println(sb.toString()); System.out.println("cdr message: " + cdrmessage); System.out.println("_________________________________________________________"); //call producer for tweet KeyedMessage<String, String> twitterdata = new KeyedMessage<String, String>( globalconfigs.getProperty("twitter4j.kafkatopic"), sb.toString()); twitterproducer.send(twitterdata); //call producer for cdr KeyedMessage<String, String> cdrmessagedata = new KeyedMessage<String, String>( globalconfigs.getProperty("cdr.kafkatopic"), cdrmessage); cdrproducer.send(cdrmessagedata); } public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } public void onScrubGeo(long userId, long upToStatusId) { } public void onException(Exception ex) { System.out.println("General Exception: shutting down Twitter sample stream..."); System.out.println(ex.getMessage()); ex.printStackTrace(); twitterStream.shutdown(); } public void onStallWarning(StallWarning warning) { } }; twitterStream.addListener(listener); // Filter stream with targeted words String filterstring = globalconfigs.getProperty("twitter4j.filterwords"); FilterQuery filterq = new FilterQuery(); filterq.track(filterstring.split(",")); twitterStream.filter(filterq); //twitterStream.sample(); }
From source file:com.illusionaryone.TwitterAPI.java
License:Open Source License
public Boolean authenticate() { com.gmt2001.Console.debug.println("Attempting to Authenticate"); try {//from w w w .j a v a 2 s .c o m ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(consumerKey); configurationBuilder.setOAuthConsumerSecret(consumerSecret); configurationBuilder.setOAuthAccessToken(oauthAccessToken); configurationBuilder.setOAuthAccessTokenSecret(oauthAccessSecret); TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build()); twitter = twitterFactory.getInstance(); accessToken = twitter.getOAuthAccessToken(); com.gmt2001.Console.out.println("Authenticated with Twitter API"); return true; } catch (TwitterException ex) { com.gmt2001.Console.err.println("Twitter Auth Failed: " + ex.getMessage()); accessToken = null; return false; } }
From source file:com.javielinux.api.loaders.ImageUploadLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {/* w w w.java 2s . c o m*/ ImageUploadResponse response = new ImageUploadResponse(); String f = Utils.appUploadImageDirectory + request.getFilename(); response.setFile(request.getFilename()); /* int size = Integer.parseInt(Utils.getPreference(mContext).getString("prf_size_photo", "2")); if (size == 1) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_SMALL); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } else if (size == 2) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_MIDDLE); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } */ response.setBmp(ImageUtils.getBitmapFromFile(f, Utils.HEIGHT_THUMB_NEWSTATUS, true)); File file = new File(f); int type = Integer.parseInt(Utils.getPreference(getContext()).getString("prf_service_image", "1")); MediaProvider mp = MediaProvider.YFROG; if (type == 1) { mp = MediaProvider.YFROG; } else if (type == 2) { mp = MediaProvider.TWITPIC; } else if (type == 3) { mp = MediaProvider.PLIXI; } loadConsumerKeys(); ConfigurationBuilder confBuild = new ConfigurationBuilder(); confBuild.setOAuthConsumerKey(consumerKey); confBuild.setOAuthConsumerSecret(consumerSecretKey); confBuild.setOAuthAccessToken(ConnectionManager.getInstance().getTwitter(request.getUserId()) .getOAuthAccessToken().getToken()); confBuild.setOAuthAccessTokenSecret(ConnectionManager.getInstance().getTwitter(request.getUserId()) .getOAuthAccessToken().getTokenSecret()); if (type == 1) { } else if (type == 2) { confBuild.setMediaProviderAPIKey("e3533af853e8f63a0018a2c63d7ee69f"); } else if (type == 3) { confBuild.setMediaProviderAPIKey("57438faa-51e4-43a5-9e15-0c63b6f73950"); } confBuild.setMediaProvider(mp.name()); Configuration config = confBuild.build(); ImageUpload upload = new ImageUploadFactory(config).getInstance(mp); if (upload != null) { response.setUrl(upload.upload(file)); return response; } else { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError("Image upload is null"); return errorResponse; } } catch (TwitterException exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } catch (Exception exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } }
From source file:com.javielinux.task.ImageUploadAsyncTask.java
License:Apache License
@Override protected ImageUploadAsyncTask.ImageUploadResult doInBackground(String... args) { ImageUploadResult iur = new ImageUploadResult(); try {/*from w w w . ja v a 2s . c om*/ String f = Utils.appUploadImageDirectory + args[0]; iur.file = args[0]; /* int size = Integer.parseInt(Utils.getPreference(mContext).getString("prf_size_photo", "2")); if (size == 1) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_SMALL); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } else if (size == 2) { Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_MIDDLE); if (resizedBitmap!=null) { FileOutputStream out = new FileOutputStream(f); resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out); } } */ iur.bmp = ImageUtils.getBitmapFromFile(f, Utils.HEIGHT_THUMB_NEWSTATUS, true); File file = new File(f); int type = Integer.parseInt(Utils.getPreference(mContext).getString("prf_service_image", "1")); MediaProvider mp = MediaProvider.YFROG; if (type == 1) { mp = MediaProvider.YFROG; } else if (type == 2) { mp = MediaProvider.TWITPIC; } else if (type == 3) { mp = MediaProvider.PLIXI; } loadConsumerKeys(); ConfigurationBuilder confBuild = new ConfigurationBuilder(); confBuild.setOAuthConsumerKey(consumerKey); confBuild.setOAuthConsumerSecret(consumerSecretKey); confBuild.setOAuthAccessToken(twitter.getOAuthAccessToken().getToken()); confBuild.setOAuthAccessTokenSecret(twitter.getOAuthAccessToken().getTokenSecret()); if (type == 1) { } else if (type == 2) { confBuild.setMediaProviderAPIKey("e3533af853e8f63a0018a2c63d7ee69f"); } else if (type == 3) { confBuild.setMediaProviderAPIKey("57438faa-51e4-43a5-9e15-0c63b6f73950"); } confBuild.setMediaProvider(mp.name()); Configuration config = confBuild.build(); ImageUpload upload = new ImageUploadFactory(config).getInstance(mp); if (upload != null) { iur.url = upload.upload(file); iur.error = false; } else { iur.error = true; } } catch (TwitterException e) { e.printStackTrace(); iur.error = true; } catch (Exception e) { e.printStackTrace(); iur.error = true; } return iur; }
From source file:com.lbarriosh.sentimentanalyzer.downloads.TweetsDownloader.java
License:Open Source License
public TweetsDownloader(String api_key, String api_secret, String access_token, String access_token_secret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(api_key);//ww w .j ava2s. com cb.setOAuthConsumerSecret(api_secret); cb.setOAuthAccessToken(access_token); cb.setOAuthAccessTokenSecret(access_token_secret); this.tf = new TwitterFactory(cb.build()); }
From source file:com.learnncode.demotwitterimagepost.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);//from ww w .j ava 2 s .c o m return; } final 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)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); twitter.updateStatus(message + " " + x); } catch (final TwitterException e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitterWithImage(Context context, final Activity callingActivity, final String imageUrl, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);/*from w ww . j a v a2 s . c o m*/ return; } final 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)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); final File file = new File(imageUrl); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); if (file.exists()) { final StatusUpdate status = new StatusUpdate(message); status.setMedia(file); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (final Exception e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitterWithInputStream(Context context, final Activity callingActivity, final InputStream inputStream, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);//from w ww . j a v a 2 s.c o m return; } final 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)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); if (inputStream != null) { final StatusUpdate status = new StatusUpdate(message); status.setMedia("GIF image", inputStream); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (final Exception e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.twitter.Utilities.TwitterHelper.java
License:Apache License
public static Twitter getTwitterInstance(Context _Context) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(_Context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder// ww w . j a va2s . c om .setOAuthConsumerSecret(_Context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(AppSettings.getTwitterAccessToken((_Context))); configurationBuilder.setOAuthAccessTokenSecret(AppSettings.getTwitterAccessTokenSecret(_Context)); Configuration configuration = configurationBuilder.build(); return new TwitterFactory(configuration).getInstance(); }
From source file:com.learnncode.twitter.Utilities.TwitterHelper.java
License:Apache License
public static Twitter getTwitterInstanceWithoutAuthentication(Context _Context) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(_Context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder//w w w .j av a 2 s. co m .setOAuthConsumerSecret(_Context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(_Context.getResources().getString(R.string.twitter_access_token)); configurationBuilder .setOAuthAccessTokenSecret(_Context.getResources().getString(R.string.twitter_access_token_secret)); Configuration configuration = configurationBuilder.build(); return new TwitterFactory(configuration).getInstance(); }