List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:gohai.simpletweet.SimpleTweet.java
License:Apache License
protected void createInstance() { ConfigurationBuilder cb = new ConfigurationBuilder(); if (oAuthConsumerKey != null) { cb.setOAuthConsumerKey(oAuthConsumerKey); }//from ww w. j a va 2 s.co m if (oAuthConsumerSecret != null) { cb.setOAuthConsumerSecret(oAuthConsumerSecret); } if (oAuthAccessToken != null) { cb.setOAuthAccessToken(oAuthAccessToken); } if (oAuthAccessTokenSecret != null) { cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); } twitter = new TwitterFactory(cb.build()).getInstance(); }
From source file:io.warp10.script.functions.TWITTERDM.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { ////ww w .j a va 2 s.c om // Extract parameters // String text = stack.pop().toString(); String recipient = stack.pop().toString(); String accessSecret = stack.pop().toString(); String accessToken = stack.pop().toString(); String consumerSecret = stack.pop().toString(); String consumerKey = stack.pop().toString(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { twitter.sendDirectMessage(recipient, text); } catch (TwitterException te) { throw new WarpScriptException("Error while sending Twitter Direct Message", te); } return stack; }
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 2s. c o 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 ww w. 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.//from w w w. ja v a 2s. 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 {//from ww w. ja va2s . c om 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:jp.xxxxxxxx.l3fish.twnyaan.service.AuthenticationService.java
License:Open Source License
/** * RequestToken????URL???????PIN???//from w ww . j a va 2 s .c om * 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.AllAPI.java
public static Configuration TwitterConnect() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//from ww w .j a v a 2 s . c om cb.setOAuthConsumerKey(CONSUMERKEY); cb.setOAuthConsumerSecret(CONSUMERSECRET); cb.setOAuthAccessToken(TOKEN); cb.setOAuthAccessTokenSecret(TOKENSECRET); return cb.build(); }
From source file:Jums.SearchTweet.java
public void main(PrintWriter out) { try {//from w w w. j a v 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();/*from w w w . j av a2 s . com*/ twitter.getHomeTimeline().forEach(s -> System.out.println("s.getText() = " + s.getText())); }