List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory()
From source file:nz.co.lolnet.james137137.lolnettwitchaddonbc.TwitterAPI.java
public TwitterAPI() { //Instantiate a re-usable and thread-safe factory TwitterFactory twitterFactory = new TwitterFactory(); //Instantiate a new Twitter instance twitter = twitterFactory.getInstance(); //setup OAuth Consumer Credentials twitter.setOAuthConsumer(consumerKey, consumerSecret); //setup OAuth Access Token twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); }
From source file:org.bonitasoft.connectors.twitter.TwitterConnector.java
License:Open Source License
@Override protected void executeConnector() throws Exception { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); if (getProxyHost() != null && getProxyPort() != null) { configurationBuilder.setHttpProxyHost(getProxyHost()); configurationBuilder.setHttpProxyPort(getProxyPort()); if (getProxyUser() != null && getProxyPass() != null) { configurationBuilder.setHttpProxyUser(getProxyUser()); configurationBuilder.setHttpProxyPassword(getProxyPass()); }//from w w w. j av a 2s . co m } Configuration configuration = new ConfigurationBuilder().build(); AccessToken token = new AccessToken(accessToken, accessTokenSecret); OAuthAuthorization authorization = new OAuthAuthorization(configuration, consumerKey, consumerSecret, token); Twitter twitter = new TwitterFactory().getInstance(authorization); executeTask(twitter); }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Authorise a new account to be accessible by Bot. * Return the request token that contains the URL that the user must use to authorise twitter. *//*w w w . j a va2 s .c o m*/ public RequestToken authorizeAccount() throws TwitterException { twitter4j.Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(getOauthKey(), getOauthSecret()); RequestToken requestToken = twitter.getOAuthRequestToken(); setConnection(twitter); return requestToken; }
From source file:org.celstec.arlearn2.oauth.OauthTwitterWorker.java
License:Open Source License
public void redirectToTwitterForAuthentication(HttpServletRequest req, HttpServletResponse resp) throws IOException { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(client_id, client_secret); RequestToken token = null;/* www . j a v a 2 s . com*/ try { token = twitter.getOAuthRequestToken(redirect_uri); req.getSession().setAttribute("requestToken", token); String loginUrl = token.getAuthenticationURL() + "&force_login=true"; resp.sendRedirect(loginUrl); } catch (TwitterException e) { e.printStackTrace(); log.log(Level.SEVERE, e.getErrorMessage(), e); } }
From source file:org.celstec.arlearn2.oauth.OauthTwitterWorker.java
License:Open Source License
public String afterSuccesfullAuthentication(HttpServletRequest request) { Twitter twitter = new TwitterFactory().getInstance(); RequestToken token = (RequestToken) request.getSession().getAttribute("requestToken"); String verifier = request.getParameter("oauth_verifier"); twitter.setOAuthConsumer(client_id, client_secret); try {/*from w ww .j a va 2 s . c o m*/ AccessToken accessToken = twitter.getOAuthAccessToken(token, verifier); User user = twitter.verifyCredentials(); AccountJDO account = AccountManager.addAccount("" + user.getId(), AccountJDO.TWITTERCLIENT, "", "", "", user.getName(), user.getProfileImageURL(), false); UserLoggedInManager.submitOauthUser(account.getUniqueId(), accessToken.getToken()); return accessToken.getToken(); } catch (TwitterException e) { log.log(Level.SEVERE, e.getMessage(), e); } return null; }
From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java
License:Apache License
/** * Get Twitter Ping.//from ww w .ja v a 2s . com * @param consumerKey consumer key * @param consumerSecret consumer secret * @return {@link RequestToken} * @throws TwitterException exception */ public RequestToken getTwitterPing() throws TwitterException { if (consumerKey == null) { throw new IllegalArgumentException("Consumer key is missing"); } if (consumerSecret == null) { throw new IllegalArgumentException("Consumer secret is missing"); } final Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); return twitter.getOAuthRequestToken(); }
From source file:org.eventjuggler.services.security.authc.social.twitter.TwitterAuthenticationMechanism.java
License:Open Source License
@Override protected Principal doAuthenticate(UserCredential credential, AuthenticationResult result) throws AuthenticationException { TwitterCredential oAuthCredential = (TwitterCredential) credential; HttpServletRequest request = oAuthCredential.getRequest(); HttpServletResponse response = oAuthCredential.getResponse(); HttpSession session = request.getSession(); Principal principal = null;/*from w w w. j a v a 2 s . c om*/ provideSecrets(oAuthCredential); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(clientID, clientSecret); //See if we are a callback RequestToken requestToken = (RequestToken) session.getAttribute(TWIT_REQUEST_TOKEN_SESSION_ATTRIBUTE); String verifier = request.getParameter("oauth_verifier"); if (requestToken != null && verifier != null) { try { AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier); session.setAttribute("accessToken", accessToken); session.removeAttribute("requestToken"); } catch (TwitterException e) { throw new AuthenticationException(e); } try { principal = new TwitterPrincipal(twitter.verifyCredentials()); checkUserInStore((TwitterPrincipal) principal); } catch (TwitterException e) { throw new AuthenticationException(e); } return principal; } try { requestToken = twitter.getOAuthRequestToken(returnURL); session.setAttribute(TWIT_REQUEST_TOKEN_SESSION_ATTRIBUTE, requestToken); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (Exception e) { throw new AuthenticationException(e); } return principal; }
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private Twitter getTwitter() { TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(authValue.getConsumerKey(), authValue.getConsumerSecret()); twitter.setOAuthAccessToken(new AccessToken(authValue.getOauthToken(), authValue.getOauthTokenSecret())); return twitter; }
From source file:org.exoplatform.extensions.twitter.services.TwitterService.java
License:Open Source License
public Twitter getTwitter() { Twitter twitter = null; twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, secretKey); return twitter; }
From source file:org.exoplatform.extensions.twitter.services.TwitterService.java
License:Open Source License
/** * /*from w w w. j a va2s. c o m*/ * @param userId * @return */ public Twitter getTwitter(String userId) { Twitter twitter = null; UserSocialNetworkPreferences prefs = this.getUserPreferences(userId); if (prefs != null) { String token = prefs.getToken(); String tokenSecret = prefs.getTokenSecret(); if (token != null && tokenSecret != null) { AccessToken accessToken = new AccessToken(token, tokenSecret); twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, secretKey); twitter.setOAuthAccessToken(accessToken); } } return twitter; }