List of usage examples for twitter4j TwitterException getMessage
@Override
public String getMessage()
From source file:org.wso2.carbon.connector.twitter.TwitterGetFriends.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }/*from w w w. j av a2 s .c o m*/ try { String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) : null; String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) : null; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); List<User> results = null; if (screenName != null && !screenName.isEmpty()) { if (count != null && !count.isEmpty()) { results = twitter.getFriendsList(screenName, Long.parseLong(count)); } else { results = twitter.getFriendsList(screenName, -1); } } else if (userID != null && !userID.isEmpty()) { if (count != null && !count.isEmpty()) { results = twitter.getFriendsList(Long.parseLong(userID), Long.parseLong(count)); } else { results = twitter.getFriendsList(Long.parseLong(userID), -1); } } if (log.isDebugEnabled()) { log.error("Retrived results : " + results.toString()); } OMElement element = this.performSearchMessages(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterGetFriendsIds.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }//from w w w . j a v a 2s. c o m try { String screenName = (TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SCREEN_NAME) : null; String userID = (TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, USER_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, USER_ID) : null; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); IDs ids = null; if (screenName != null && !screenName.isEmpty()) { if (count != null && !count.isEmpty()) { ids = twitter.getFriendsIDs(screenName, Long.parseLong(count)); } else { ids = twitter.getFriendsIDs(screenName, -1); } } else if (userID != null && !userID.isEmpty()) { if (count != null && !count.isEmpty()) { ids = twitter.getFriendsIDs(Long.parseLong(userID), Long.parseLong(count)); } else { ids = twitter.getFriendsIDs(Long.parseLong(userID), -1); } } if (log.isDebugEnabled()) { log.error("Retrived result: " + ids.toString()); } OMElement element = this.performSearchMessages(ids.getIDs()); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterGetSentDirectMessages.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }/* ww w . j a va2 s.c o m*/ try { String page = (TwitterUtils.lookupTemplateParamater(messageContext, PAGE) != null && !TwitterUtils.lookupTemplateParamater(messageContext, PAGE).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, PAGE) : null; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; String sinceID = (TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) : null; String maxID = (TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); List<DirectMessage> results = null; if (page != null && !page.isEmpty()) { if (count == null && sinceID == null && maxID == null) { results = twitter.getDirectMessages(new Paging(Long.parseLong(page))); } else if (count != null && sinceID == null && maxID == null) { results = twitter .getSentDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count))); } else if (count != null && sinceID != null && maxID == null) { results = twitter.getSentDirectMessages( new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID))); } else { results = twitter.getSentDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID), Long.parseLong(maxID))); } } else if (page == null && sinceID != null) { results = twitter.getSentDirectMessages(new Paging(Integer.parseInt(sinceID))); } else { results = twitter.getSentDirectMessages(); } OMElement element = this.performSearchMessages(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterHomeTimeLine.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }/* w ww .j av a 2 s. co m*/ try { String page = (TwitterUtils.lookupTemplateParamater(messageContext, PAGE) != null && !TwitterUtils.lookupTemplateParamater(messageContext, PAGE).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, PAGE) : "1"; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; String sinceID = (TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) : null; String maxID = (TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); List<Status> results = null; if (page != null && !page.isEmpty()) { if (count == null && sinceID == null && maxID == null) { results = twitter.getHomeTimeline(new Paging(Long.parseLong(page))); } else if (count != null && sinceID == null && maxID == null) { results = twitter.getHomeTimeline(new Paging(Integer.parseInt(page), Integer.parseInt(count))); } else if (count != null && sinceID != null && maxID == null) { results = twitter.getHomeTimeline( new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID))); } else { results = twitter.getHomeTimeline(new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID), Long.parseLong(maxID))); } } else if (page == null && sinceID != null) { results = twitter.getHomeTimeline(new Paging(Integer.parseInt(sinceID))); } else { results = twitter.getHomeTimeline(); } OMElement element = this.performSearch(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterMentionsTimeLine.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }//ww w .jav a 2 s. c om try { List<Status> results = null; String page = (TwitterUtils.lookupTemplateParamater(messageContext, PAGE) != null && !TwitterUtils.lookupTemplateParamater(messageContext, PAGE).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, PAGE) : "1"; String count = (TwitterUtils.lookupTemplateParamater(messageContext, COUNT) != null && !TwitterUtils.lookupTemplateParamater(messageContext, COUNT).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, COUNT) : null; String sinceID = (TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, SINCE_ID) : null; String maxID = (TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) != null && !TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID).isEmpty()) ? TwitterUtils.lookupTemplateParamater(messageContext, MAX_ID) : null; Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); if (page != null && !page.isEmpty()) { if (count == null && sinceID == null && maxID == null) { results = twitter.getMentionsTimeline(new Paging(Long.parseLong(page))); } else if (count != null && sinceID == null && maxID == null) { results = twitter .getMentionsTimeline(new Paging(Integer.parseInt(page), Integer.parseInt(count))); } else if (count != null && sinceID != null && maxID == null) { results = twitter.getMentionsTimeline( new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID))); } else { results = twitter.getMentionsTimeline(new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID), Long.parseLong(maxID))); } } else if (page == null && sinceID != null) { results = twitter.getMentionsTimeline(new Paging(Integer.parseInt(sinceID))); } else { results = twitter.getMentionsTimeline(); } OMElement element = this.performSearch(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterRetweetsofMine.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }//from w w w.j av a2 s .com try { String page = TwitterUtils.lookupTemplateParamater(messageContext, PAGE); Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); List<Status> results = null; if (page != null && !page.isEmpty()) { results = twitter.getRetweetsOfMe(new Paging(Long.parseLong(page))); } else { results = twitter.getRetweetsOfMe(); } OMElement element = this.performSearch(results); super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterRetweetStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {/* w w w . ja v a 2 s . com*/ String id = TwitterUtils.lookupTemplateParamater(messageContext, ID); Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.retweetStatus(Long.parseLong(id)); TwitterUtils.storeResponseStatus(messageContext, status); if (log.isDebugEnabled()) { log.info("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { log.error("Failed to retweet status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterSearchPlaces.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { // TODO Auto-generated method stub if (log.isDebugEnabled()) { log.info("executing twitter search places"); }// w ww.ja v a 2 s .c o m try { String latitude = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_BY_LATITUDE); String longitude = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_LONGITUDE); String ip = TwitterUtils.lookupTemplateParamater(messageContext, SEARCH_IP); GeoQuery query = new GeoQuery( new GeoLocation(Double.parseDouble(latitude), Double.parseDouble(longitude))); Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); OMElement element = this.performSearch(twitter, query); if (log.isDebugEnabled()) { log.info("executing prparing soap envolope" + element.toString()); } super.preparePayload(messageContext, element); } catch (TwitterException te) { log.error("Failed to search twitter : " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } catch (Exception te) { log.error("Failed to search generic: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.connector.twitter.TwitterUpdateStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {//from w ww .java 2 s .c o m String statusStr = TwitterUtils.lookupTemplateParamater(messageContext, STATUS); if (statusStr == null || "".equals(statusStr.trim())) { return; } Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.updateStatus(statusStr); TwitterUtils.storeResponseStatus(messageContext, status); } catch (TwitterException te) { log.error("Failed to show status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.wso2.carbon.identity.authenticator.twitter.TwitterAuthenticator.java
License:Open Source License
/** * Initiate the authentication request//w w w.ja v a 2 s .c o m */ @Override protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); Map<String, String> authenticatorProperties = context.getAuthenticatorProperties(); String apiKey = authenticatorProperties.get(TwitterAuthenticatorConstants.TWITTER_API_KEY); String apiSecret = authenticatorProperties.get(TwitterAuthenticatorConstants.TWITTER_API_SECRET); configurationBuilder.setIncludeEmailEnabled(true); Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance(); twitter.setOAuthConsumer(apiKey, apiSecret); try { String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier()); String callbackURL = getCallbackUrl(authenticatorProperties); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); String subStr = queryParams .substring(queryParams.indexOf(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "=")); String sessionDK = subStr .substring(subStr.indexOf(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "="), subStr.indexOf("&")) .replace((TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY + "="), ""); request.getSession().setAttribute(TwitterAuthenticatorConstants.TWITTER_SESSION_DATA_KEY, sessionDK); request.getSession().setAttribute(TwitterAuthenticatorConstants.TWITTER_REQUEST_TOKEN, requestToken); request.getSession().setAttribute(TwitterAuthenticatorConstants.AUTHENTICATOR_NAME.toLowerCase(), twitter); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { log.error("Exception while sending to the Twitter login page.", e); throw new AuthenticationFailedException(e.getMessage(), e); } catch (IOException e) { log.error("Exception while sending to the Twitter login page.", e); throw new AuthenticationFailedException(e.getMessage(), e); } }