List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:it.greenvulcano.gvesb.social.twitter.TwitterSocialAdapterAccount.java
License:Open Source License
/** * This method returns the interface class towards Twitter, already instantiated with the * account's tokens//from ww w. j a v a 2 s . co m * * @return {@link Twitter} */ public Twitter getProxyObject() { if (twitter != null) { return twitter; } else { // setting OAuth tokens ConfigurationBuilder confBuilder = new ConfigurationBuilder(); if (proxy != null) { confBuilder.setHttpProxyHost(proxy.getHttpProxyHost()); confBuilder.setHttpProxyPort(proxy.getHttpProxyPort()); confBuilder.setHttpProxyUser(proxy.getHttpProxyUser()); confBuilder.setHttpProxyPassword(proxy.getHttpProxyPassword()); } confBuilder.setOAuthConsumerKey(consumerKey); confBuilder.setOAuthConsumerSecret(consumerSecret); confBuilder.setOAuthAccessToken(accessToken); confBuilder.setOAuthAccessTokenSecret(accessTokenSecret); Configuration config = confBuilder.build(); // instantiating Twitter object this.twitter = new TwitterFactory(config).getInstance(); } logger.info("got TwitterFactory instance."); return twitter; }
From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java
License:Open Source License
/** * Method that return the Twitter object that allows the access to the * Twitter API/*from w ww. ja va2 s .c om*/ * * @param user the user in MeteoCal * @return null if there was a problem with the creation of the Twitter * object */ public static Twitter getTwitterObject(User user) { Twitter twitter; if (user.getTwitterToken() == null) { // Twitter not connected return null; } ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(CLIENT_ID); builder.setOAuthConsumerSecret(CLIENT_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); AccessToken at = new AccessToken(user.getTwitterToken(), user.getTwitterTokenSecret()); LOGGER.log(Level.INFO, at); try { twitter.setOAuthAccessToken(at); } catch (Exception e) { LOGGER.log(Level.ERROR, e); return null; } return twitter; }
From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java
License:Open Source License
/** * Default constructor.//w ww .j a va 2 s. co m */ public HandleAuthTwitterImpl() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(CLIENT_ID); builder.setOAuthConsumerSecret(CLIENT_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); cont = 0; }
From source file:it.polimi.meteocal.ejb.HandleAuthTwitterImpl.java
License:Open Source License
@Override public String getUrlLoginTwitter() { String urlLogin = "error.xhtml"; try {/* www .jav a 2 s .c o m*/ ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(CLIENT_ID); builder.setOAuthConsumerSecret(CLIENT_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); //if (requestToken == null) { requestToken = twitter.getOAuthRequestToken(URL_BASE + "/MeteoCal-web/loginTwitter.xhtml"); //} urlLogin = requestToken.getAuthenticationURL(); } catch (TwitterException e) { LOGGER.log(Level.ERROR, e); } cont++; LOGGER.log(Level.INFO, "Conteggio: " + cont); LOGGER.log(Level.INFO, "URL LOGIN " + urlLogin); return urlLogin; }
From source file:JavaFiles.TwitterAPI.java
public TwitterAPI() { cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("53nUEtaL8hsyBS7HyCLZsdj5O") .setOAuthConsumerSecret("5ZJ8TeXWj7zHOhK1OtvqxmjD0dIrHUjmtZ7rLOYc9cK0ovDcTF") .setOAuthAccessToken("576227678-tDF0uPGF3bjCAFgB7CVRcAXCLWSm7pc7dgEzLVea") .setOAuthAccessTokenSecret("LKHdmnEhlTPXkgZrI0jYejrOkhtcJTvf7Gz3kIBCeoFu7"); tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();// w w w . j a va2 s .co m }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetMultiple.java
License:Open Source License
private final String init_user_oauth(final int index) { oauthToken = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_" + index, "")); if (oauthToken.equals("")) { WriteLog.write(this, "oauthToken.equals(\"\")"); final SharedPreferences.Editor editor = pref_twtr.edit(); editor.putString("index", "0"); editor.remove("consumer_key_" + index); editor.remove("consumer_secret_" + index); editor.remove("oauth_token_" + index); editor.remove("oauth_token_secret_" + index); editor.remove("profile_image_url_" + index); editor.remove("screen_name_" + index); editor.remove("status_" + index); editor.commit();/*from w ww . j a va 2 s .com*/ } consumerKey = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_key_" + index, "")); consumerSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_secret_" + index, "")); if (consumerKey.equals("") || consumerSecret.equals("")) { WriteLog.write(this, "(consumerKey.equals(\"\") || consumerSecret.equals(\"\"))"); consumerKey = getString(R.string.default_consumerKey); consumerSecret = getString(R.string.default_consumerSecret); } pref_app = PreferenceManager.getDefaultSharedPreferences(this); pref_timeout_t4j_connection = ListAdapter.getPrefInt(this, "pref_timeout_t4j_connection", "20000"); pref_timeout_t4j_read = ListAdapter.getPrefInt(this, "pref_timeout_t4j_read", "120000"); oauthTokenSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_secret_" + index, "")); try { confbuilder = new ConfigurationBuilder(); } catch (final IllegalStateException e) { WriteLog.write(this, e); } catch (final Exception e) { WriteLog.write(this, e); } confbuilder.setOAuthAccessToken(oauthToken).setOAuthAccessTokenSecret(oauthTokenSecret) .setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setHttpConnectionTimeout(pref_timeout_t4j_connection).setHttpReadTimeout(pref_timeout_t4j_read) .setHttpRetryCount(3).setHttpRetryIntervalSeconds(10);// .setUseSSL(true); Twitter twtr; try { conf = confbuilder.build(); twtr = new TwitterFactory(conf).getInstance(); } catch (final Exception e) { twtr = null; WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } WriteLog.write(this, "init_user_oauth(): conf: " + conf.toString()); WriteLog.write(this, "init_user_oauth(): twtr: " + twtr.toString()); if (twtr != null) { try { screenName = twtr.getScreenName(); User user = twtr.showUser(screenName); final String profile_image_url = user.getProfileImageURL().toString(); pref_twtr = getSharedPreferences("Twitter_setting", MODE_PRIVATE); final SharedPreferences.Editor editor = pref_twtr.edit(); editor.putString("screen_name_" + index, screenName); editor.putString("profile_image_url_" + index, profile_image_url); editor.commit(); WriteLog.write(this, "screenName: " + screenName); WriteLog.write(this, "profile_image_url: " + profile_image_url); } catch (final TwitterException e) { WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } catch (final Exception e) { WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } } return screenName; }
From source file:jp.xxxxxxxx.l3fish.twnyaan.service.AuthenticationService.java
License:Open Source License
/** * RequestToken????URL???????PIN???//from w w w.j av a2s. co m * RequestToken??????{@code null}? * * @return ???RequestToken??????????{@code null} */ public RequestToken authorize() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(TwitterAPIKey.getConsumerKey()) .setOAuthConsumerSecret(TwitterAPIKey.getConsumerSecret()); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); RequestToken requestToken = null; try { requestToken = twitter.getOAuthRequestToken(); URI authorizationURI = new URI(requestToken.getAuthorizationURL()); Desktop desktop = Desktop.getDesktop(); desktop.browse(authorizationURI); } catch (URISyntaxException | IOException e) { System.err.println(ErrorCode.CANNOT_OPEN_AUTHORIZATION_URI); } catch (TwitterException e) { System.err.println(ErrorCode.TWITTER_SERVICE_UNAVAILABLE); } return requestToken; }
From source file:Jums.SearchTweet.java
public void main(PrintWriter out) { try {//from w ww .j av a 2 s. c o m ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(CONSUMERKEY); cb.setOAuthConsumerSecret(CONSUMERSECRET); cb.setOAuthAccessToken(TOKEN); cb.setOAuthAccessTokenSecret(TOKENSECRET); Twitter tw = new TwitterFactory(cb.build()).getInstance(); User user = tw.verifyCredentials(); List<Status> statuses = tw.getHomeTimeline(); for (Status s : statuses) { } } catch (Exception e) { e.printStackTrace(); } }
From source file:junit.org.rapidpm.module.iot.twitter.TwitterInitApp.java
License:Apache License
public static void main(String[] args) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3") .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip") .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7") .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();// w w w . jav a 2s .c o m twitter.getHomeTimeline().forEach(s -> System.out.println("s.getText() = " + s.getText())); }
From source file:keypoh.TwitterCrawler.java
/** * Constructor//from w w w .j av a 2s . c o m * @param config * @throws Exception */ TwitterCrawler(ConfigurationBuilder config) throws Exception { Configure(config); tw = new TwitterFactory(config.build()).getInstance(); tw.setOAuthConsumer("4Fe696sYfk2pZjmmncAaZJQUR", "F25etIib277GtJDK5qIXzC8N4YdZ3Fh8w7Bg2otwqt2EDHQabj"); // tw.setOAuthAccessToken(token); OAuth2Token tok = tw.getOAuth2Token(); }