List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
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);/* ww w . ja v 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(); }
From source file:com.tweet.HelperMethods.java
License:Apache License
public static void postToTwitterWithImage(Context context, final Activity callingActivity, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);//w w w.j a v a 2 s . co 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(); //final File file = new File(imageUrl); new Thread(new Runnable() { @Override public void run() { boolean success = true; try { if (StaticData.graphFile.exists()) { Calendar cal = Calendar.getInstance(); StatusUpdate status = new StatusUpdate(message + "\n@" + cal.getTime().toString()); status.setMedia(StaticData.graphFile); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (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.tweet.LoginActivity.java
License:Apache License
private void askOAuth() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(twitterConsumerKey); configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret); Configuration configuration = configurationBuilder.build(); twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { @Override// w w w . ja va 2 s . c om 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() { mAlertBuilder.cancel(); Toast.makeText(LoginActivity.this, errorString.toString(), Toast.LENGTH_SHORT).show(); finish(); } }); return; } LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { twitterLoginWebView.loadUrl(requestToken.getAuthenticationURL()); } }); } }).start(); }
From source file:com.tweetmyhome.TweetMyHome.java
public TweetMyHome() throws TweetMyHomeException, IOException, TweetStringException { Log.setLogger(new MyCustomLogger()); p = new TweetMyHomeProperties(); if (!p.isFirstTimeCreated()) { if (p.getValueByKey(Key.debuggin).equalsIgnoreCase("true")) { Log.set(Log.LEVEL_DEBUG);//from w ww . jav a 2 s.c o m Log.set(Log.LEVEL_TRACE); } else { Log.set(Log.LEVEL_INFO); } } else { File file = new File(TweetMyHomeProperties.FILE_NAME); info(String.format("Properties file created at: %s", file.getAbsolutePath())); info(String.format("Please edit '%s' to correct aplication function", TweetMyHomeProperties.FILE_NAME)); info("Exiting aplication..."); System.exit(0); } tweetCount = new TweetMensajeCount(COUNT_FILE); tmh_device_xml = XMLFilesManager.getTweetMyHomeDevices(); if (tmh_device_xml == null) { throw new TweetMyHomeException( "Fail to read [" + XMLFilesManager.TWEET_MY_HOME_DEVICES_XML_FILE + "] file"); } tmh_dic_xml = XMLFilesManager.getTweetMyHomeDictionaryCommand(); if (tmh_dic_xml == null) { throw new TweetMyHomeException( "Fail to read [" + XMLFilesManager.TWEET_MY_HOME_DICTIONARY_XML_FILE + "] file"); } tweetDictionary = new TweetStringDictionary(tmh_dic_xml); trace("XML Files already Readed [" + XMLFilesManager.TWEET_MY_HOME_DEVICES_XML_FILE + "," + XMLFilesManager.TWEET_MY_HOME_DICTIONARY_XML_FILE + "]"); if (!NetUtil.isConnectedToInternet() && INTERNET_REQUIRED_DEV) { throw new TweetMyHomeException("Not Connected to Internet"); } trace("Internet conecction detected"); trace("Trying to connect to DBMS..."); db = new TweetMyHomeDatabase(p); if (!db.connect()) { throw new TweetMyHomeException("Not Connected to DBMS"); } trace("Connected to DBMS"); db.addTweetMyHomeDevices(tmh_device_xml); if (RASPBERRY_ON_BOARD) { if (p.getValueByKey(Key.arduinoIOBridge).equalsIgnoreCase("true")) { throw new TweetMyHomeException("Arduino not supported..."); } else { iob = new RaspberryPiGPIO(tmh_device_xml); } if (iob != null) { iob.addIODeviceListener(this); iob.connect(); trace("GPIO Link established"); com = new Comunity(false, iob); sec = new Security(false, iob); //sect = new SecurityThreshhold(sec); trace("Security , Security threshold & Comunity initiated"); } } else { warn("Raspberry PI GPIO omited. APP prob. won't work well"); } sect = new SecurityThreshhold(sec); trace("Setting Twitter OAuth parameters..."); ConfigurationBuilder cb1 = new ConfigurationBuilder(); cb1.setDebugEnabled(false).setOAuthConsumerKey("RaTG5hw5OwhQQugghtLthG0ug") .setOAuthConsumerSecret("brJ0vcrdGnCHMTxDCmKoThPpJubD6e2xol5WjdO9bBa19nzkXp") .setOAuthAccessToken("3236804811-V6MOxfbox4jVylx6pDjkR9UrEpuPzZyOwkaVIWp") .setOAuthAccessTokenSecret("33HvizelxmGN700a7pLa6YBKv0l2uTMLoJK593MlXellg"); ConfigurationBuilder cb2 = new ConfigurationBuilder(); cb2.setDebugEnabled(false).setOAuthConsumerKey("RaTG5hw5OwhQQugghtLthG0ug") .setOAuthConsumerSecret("brJ0vcrdGnCHMTxDCmKoThPpJubD6e2xol5WjdO9bBa19nzkXp") .setOAuthAccessToken("3236804811-V6MOxfbox4jVylx6pDjkR9UrEpuPzZyOwkaVIWp") .setOAuthAccessTokenSecret("33HvizelxmGN700a7pLa6YBKv0l2uTMLoJK593MlXellg"); TwitterFactory tf = new TwitterFactory(cb1.build()); TwitterStreamFactory sf = new TwitterStreamFactory(cb2.build()); trace("Connecting to Twitter STREAM API..."); tws = sf.getInstance(); tws.addListener(this); tws.user(); trace("Connecting to Twitter REST API..."); tw = tf.getInstance(); debug("Contructor fi"); /*----------------NEEDED WORK TO DO-------------------*/ // integrityCheckSuperAdmin(); }
From source file:com.twitter.storm.hashtag2.TwitterSampleSpout.java
License:Apache License
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;/*from w w w . j a v a 2 s .c o m*/ StatusListener listener = new StatusListener() { public void onStatus(Status status) { queue.offer(status); } public void onDeletionNotice(StatusDeletionNotice sdn) { } public void onTrackLimitationNotice(int i) { } public void onScrubGeo(long l, long l1) { } public void onException(Exception ex) { } public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); _twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); _twitterStream.addListener(listener); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }
From source file:com.twitter.TwitterClient.java
public Configuration getConfiguration() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setJSONStoreEnabled(true).setOAuthConsumerKey(OAUTHCONSUMERKEY).setOAuthConsumerSecret(OAUTHCONSECRET) .setOAuthAccessToken(OAUTHACCESSTOKEN).setOAuthAccessTokenSecret(OAUTHACCESSTOKENSECRET); Configuration configuration = cb.build(); return configuration; }
From source file:com.twitter4rk.TwitterAuthFragment.java
License:Apache License
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mTwitterWebView = new WebView(getActivity()); final Bundle args = getArguments(); if (args == null) { // This wont be case because startTwitterAuth() handles args for // fragment throw new IllegalArgumentException( "No arguments passed to fragment, Please use startTwitterAuth(...) method for showing this fragment"); }//from w w w . j a v a 2s .com // Get builder from args mBuilder = args.getParcelable(BUILDER_KEY); // Hide action bar if (mBuilder.hideActionBar) mBuilder.activity.getActionBar().hide(); // Init progress dialog mProgressDialog = new ProgressDialog(mBuilder.activity); mProgressDialog.setMessage(mBuilder.progressText == null ? "Loading ..." : mBuilder.progressText); if (mBuilder.isProgressEnabled) mProgressDialog.show(); // Init ConfigurationBuilder twitter4j final ConfigurationBuilder cb = new ConfigurationBuilder(); if (mBuilder.isDebugEnabled) cb.setDebugEnabled(true); cb.setOAuthConsumerKey(mBuilder.consumerKey); cb.setOAuthConsumerSecret(mBuilder.consumerSecret); // Web view client to handler url loading mTwitterWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // Get url first final Uri uri = Uri.parse(url); // Check if we need to see for callback URL if (mBuilder.callbackUrl != null && url.contains(mBuilder.callbackUrl)) { // Get req info String oauthToken = uri.getQueryParameter("oauth_token"); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (mListener != null) mListener.onSuccess(oauthToken, oauthVerifier); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); mIsAuthenticated = true; removeMe(); return true; // If no callback URL then check for info directly } else if (uri.getQueryParameter("oauth_token") != null && uri.getQueryParameter("oauth_verifier") != null) { // Get req info String oauthToken = uri.getQueryParameter("oauth_token"); String oauthVerifier = uri.getQueryParameter("oauth_verifier"); if (mListener != null) mListener.onSuccess(oauthToken, oauthVerifier); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); mIsAuthenticated = true; removeMe(); return true; // If nothing then its failure } else { // Notify user if (mListener != null) mListener.onFailure( new Exception("Couldn't find the callback URL or oath parameters in response")); if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null) getActivity().getActionBar().show(); removeMe(); return false; } } }); // Web Crome client to handler progress dialog visibility mTwitterWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { if (mProgressDialog.isShowing()) mProgressDialog.dismiss(); } } }); final Handler handler = new Handler(); new Thread(new Runnable() { @Override public void run() { try { final TwitterFactory twitterFactory = new TwitterFactory(cb.build()); final Twitter twitter = twitterFactory.getInstance(); RequestToken requestToken = null; if (mBuilder.callbackUrl == null) requestToken = twitter.getOAuthRequestToken(); else requestToken = twitter.getOAuthRequestToken(mBuilder.callbackUrl); final RequestToken finalRequestToken = requestToken; handler.post(new Runnable() { @Override public void run() { final String url = finalRequestToken.getAuthorizationURL(); mTwitterWebView.loadUrl(url); } }); } catch (TwitterException e) { e.printStackTrace(); } } }).start(); return mTwitterWebView; }
From source file:com.unisa.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. *//* w w w . j a v a 2 s . c o m*/ @Override public void configure(Context context) { 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 keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, ""); if (keywordString.trim().length() == 0) { keywords = new String[0]; } else { keywords = keywordString.split(","); for (int i = 0; i < keywords.length; i++) { keywords[i] = keywords[i].trim(); } } 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.vuze.client.plugins.twitter.TwitterPlugin.java
License:Open Source License
private TwitterResult sendTweet(String status) { TwitterResult twitter_result;// w w w .j a v a 2 s. com log.log("Updating status: " + status); try { ConfigurationBuilder cb = new ConfigurationBuilder(); //cb.setSource( "Vuze" ); // Twitter twitter = new TwitterFactory( cb.build()).getInstance( twitter_user.getValue(), new String( twitter_password.getValue())); Status result; Twitter twitter = null; try { if (access_token == null) { throw (new Exception("Please configure your account settings in the plugin options")); } cb.setOAuthAccessToken(access_token.getToken()) .setOAuthAccessTokenSecret(access_token.getTokenSecret()).setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET); twitter = new TwitterFactory(cb.build()).getInstance(); result = twitter.updateStatus(status); } catch (Throwable e) { // hack for old clients that don't have correct trust store if (twitter != null && (e instanceof TwitterException) && ((TwitterException) e).getStatusCode() == -1) { String truststore_name = FileUtil.getUserFile(SESecurityManager.SSL_CERTS).getAbsolutePath(); File target = new File(truststore_name); if (!target.exists() || target.length() < 2 * 1024) { File cacerts = new File( new File(new File(System.getProperty("java.home"), "lib"), "security"), "cacerts"); if (cacerts.exists()) { FileUtil.copyFile(cacerts, target); } } // this merely acts to trigger a load of the keystore plugin_interface.getUtilities().getSecurityManager() .installServerCertificate(new URL("https://twitter.com/")); result = twitter.updateStatus(status); } else { throw (e); } } log.log("Status updated to '" + result.getText() + "'"); twitter_result = new TwitterResult(); } catch (TwitterException e) { int status_code = e.getStatusCode(); if (status_code == 401) { log.logAlert(LoggerChannel.LT_ERROR, "Twitter status update failed: id or password incorrect"); twitter_result = new TwitterResult("Authentication failed: ID or password incorrect", false); } else if (status_code == 403) { log.logAlert(LoggerChannel.LT_ERROR, "Twitter status update failed: duplicate tweet rejected by the server"); twitter_result = new TwitterResult("Tweet has already been sent!", false); } else if (status_code >= 500 && status_code < 600) { log.logAlert(LoggerChannel.LT_ERROR, "Twitter status update failed: Twitter is down or being upgraded"); twitter_result = new TwitterResult("Tweet servers unavailable - try again later", true); } else { log.logAlert("Twitter status update failed", e); twitter_result = new TwitterResult(Debug.getNestedExceptionMessage(e), false); } } catch (Throwable e) { log.logAlert("Twitter status update failed", e); twitter_result = new TwitterResult(Debug.getNestedExceptionMessage(e), false); } return (twitter_result); }
From source file:com.wavemaker.runtime.ws.TwitterFeedService.java
License:Open Source License
private Twitter getTwitter() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(OAuthConsumerKey).setOAuthConsumerSecret(OAuthConsumerSecret) .setOAuthAccessToken(OAuthAccessToken).setOAuthAccessTokenSecret(OAuthAccessTokenSecret); return new TwitterFactory(cb.build()).getInstance(); }