List of usage examples for twitter4j Paging Paging
public Paging(long sinceId)
From source file:org.junjun.twitter.GetUserTimeline.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetUserTimeline * * @param args String[]/*from ww w.j a v a 2 s. c o m*/ */ public static void main(String[] args) { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; String user; Paging paging = new Paging(1); paging.setCount(100); if (args.length == 1) { user = args[0]; /* statuses = twitter.getUserTimeline(Long.parseLong(user),paging);*/ statuses = twitter.getUserTimeline(Long.parseLong(user)); } else { user = twitter.verifyCredentials().getScreenName(); statuses = twitter.getUserTimeline(); } System.out.println("Showing @" + user + "'s user timeline."); int i = 0; for (Status status : statuses) { System.out.println(i++ + "@" + status.getUser().getName() + " - " + status + " "); } System.out.println(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:org.komusubi.feeder.sns.twitter.HistoryPage.java
License:Apache License
/** * create new instance./*from ww w .java 2 s. co m*/ * @param timeline */ public HistoryPage(Twitter twitter, int currentPage) { this.twitter = twitter; this.current = new Paging(currentPage); }
From source file:org.springframework.integration.twitter.InboundDMStatusEndpoint.java
License:Apache License
@Override protected void refresh() throws Exception { this.runAsAPIRateLimitsPermit(new ApiCallback<InboundDMStatusEndpoint>() { public void run(InboundDMStatusEndpoint t, Twitter twitter) throws Exception { forwardAll((!hasMarkedStatus()) ? t.twitter.getDirectMessages() : t.twitter.getDirectMessages(new Paging(t.getMarkerId()))); }// w w w . j a v a 2 s . com }); }
From source file:org.springframework.integration.twitter.InboundMentionStatusEndpoint.java
License:Apache License
@Override protected void refresh() throws Exception { this.runAsAPIRateLimitsPermit(new ApiCallback<InboundMentionStatusEndpoint>() { public void run(InboundMentionStatusEndpoint ctx, Twitter twitter) throws Exception { forwardAll((!hasMarkedStatus()) ? twitter.getMentions() : twitter.getMentions(new Paging(ctx.getMarkerId()))); }//from www . j a v a 2 s .com }); }
From source file:org.springframework.integration.twitter.InboundUpdatedStatusEndpoint.java
License:Apache License
@Override protected void refresh() throws Exception { this.runAsAPIRateLimitsPermit(new ApiCallback<InboundUpdatedStatusEndpoint>() { public void run(InboundUpdatedStatusEndpoint t, Twitter twitter) throws Exception { forwardAll((!t.hasMarkedStatus()) ? twitter.getFriendsTimeline() : twitter.getFriendsTimeline(new Paging(t.getMarkerId()))); }/* www. java 2s . c o m*/ }); }
From source file:org.wso2.carbon.connector.twitter.TwitterGetDirectMessages.java
License:Open Source License
@Override public void connect(MessageContext messageContext) throws ConnectException { if (log.isDebugEnabled()) { log.info("executing twitter get user time line"); }/* www .j av a2s .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 .getDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count))); } else if (count != null && sinceID != null && maxID == null) { results = twitter.getDirectMessages( new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID))); } else { results = twitter.getDirectMessages(new Paging(Integer.parseInt(page), Integer.parseInt(count), Long.parseLong(sinceID), Long.parseLong(maxID))); } } else if (page == null && sinceID != null) { results = twitter.getDirectMessages(new Paging(Integer.parseInt(sinceID))); } else { results = twitter.getDirectMessages(); } 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.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"); }/* w w w .j a v a 2 s. co 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 w w. ja v a 2s . c o 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"); }/*w w w . ja v a 2 s. co m*/ 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 a v a 2 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); } }