List of usage examples for twitter4j Twitter getHomeTimeline
ResponseList<Status> getHomeTimeline(Paging paging) throws TwitterException;
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private ResponseList<Status> getResponseList() { LOG.debug("called."); long cursol = -1; int listId = 0; int count = 50; int pageNumber = 1; Paging paging = new Paging(pageNumber, count); try {//w w w. j av a 2 s .c o m // TODO: polymorphism to here? -> plugin. // home if (paramValue.getResponseListMode().equals("home")) { Twitter twitter = getTwitter(); return twitter.getHomeTimeline(paging); } // user if (paramValue.getResponseListMode().equals("user")) { Twitter twitter = getTwitter(); return twitter.getUserTimeline(paging); } // list if (paramValue.getResponseListMode().equals("list")) { if (paramValue.getUserListName().length() != 0) { Twitter twitter = getTwitter(); PagableResponseList<UserList> lists = twitter.getUserLists(twitter.getScreenName(), cursol); for (UserList list : lists) { String listFullName = list.getFullName(); if (listFullName.equals(paramValue.getUserListName())) { listId = list.getId(); return twitter.getUserListStatuses(listId, paging); } } } } // default.. Twitter twitter = getTwitter(); return twitter.getHomeTimeline(); } catch (TwitterException te) { // TODO: transition to an error page here? throw new RuntimeException(te); } }
From source file:org.rhq.plugins.twitter.TwitterComponent.java
License:Open Source License
/** * Gather measurement data// w w w. j a va2 s .co m * @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set) */ public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { Twitter twitter = createTwitterInstance(); for (MeasurementScheduleRequest req : metrics) { if (req.getName().equals("tweetCount")) { // Twitter twitter = new Twitter(username,password,serverUrl); Paging paging = new Paging(); if (lastId == NOT_YET_SET) { paging.setSinceId(1); paging.setCount(1); } else { paging.setSinceId(lastId); paging.setCount(100); } List<Status> statuses; statuses = twitter.getHomeTimeline(paging); if (lastId > 0) { MeasurementDataNumeric res; res = new MeasurementDataNumeric(req, (double) statuses.size()); eventPoller.addStatuses(statuses); report.addData(res); } if (statuses.size() > 0) lastId = statuses.get(0).getId(); // This is always newest first } else if (req.getName().equals("followerCount")) { int count = twitter.getFollowersIDs(-1).getIDs().length; MeasurementDataNumeric res; res = new MeasurementDataNumeric(req, (double) count); report.addData(res); } } }
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"); }/*from w w w . j av a 2s . 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:Origin.Timeline.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/* w ww . j a v a 2s . co m*/ cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); try { Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); Paging paging = new Paging(1, 200); ResponseList<Status> userstatus = twitter.getHomeTimeline(paging); request.setAttribute("userstatus", userstatus); request.getRequestDispatcher("/timeline.jsp").forward(request, response); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }