List of usage examples for twitter4j Paging setPage
public void setPage(int page)
From source file:com.marpies.ane.twitter.functions.GetSentDirectMessagesFunction.java
License:Apache License
private Paging getPaging(int count, long sinceID, long maxID, int page) { Paging paging = null; if (count != 20) { paging = new Paging(); paging.setCount(count);// w w w . j a va 2s .c om } if (sinceID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setSinceId(sinceID); } if (maxID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setMaxId(maxID); } if (page > 0) { paging = (paging == null) ? new Paging() : paging; paging.setPage(page); } return paging; }
From source file:com.test.GetDirectMessages.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessage.GetDirectMessages * * @param args String[]//from w ww.jav a 2s .c o m */ public static void main(String[] args) { // Twitter twitter = new TwitterFactory().getInstance(); Twitter twitter = AccountTwitterFactory.getWiseManTwitter(); try { Paging paging = new Paging(1); List<DirectMessage> messages; do { messages = twitter.getDirectMessages(paging); for (DirectMessage message : messages) { System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - " + message.getText()); } paging.setPage(paging.getPage() + 1); } while (messages.size() > 0 && paging.getPage() < 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); System.exit(-1); } }
From source file:examples.GetUserListStatuses.java
License:Apache License
/** * Usage: java twitter4j.examples.list.GetUserListStatuses [list id] * * @param args message// w w w. ja v a2 s . c o m */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.list.GetUserListStatuses [list id]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); Paging page = new Paging(1); ResponseList<Status> statuses; do { statuses = twitter.getUserListStatuses(Integer.parseInt(args[0]), page); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } page.setPage(page.getPage() + 1); } while (statuses.size() > 0 && page.getPage() <= 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to list statuses: " + te.getMessage()); System.exit(-1); } }
From source file:jp.wda.azeda.core.daemons.impl.RetweetsCrawlerImpl.java
License:Apache License
/** * * @param twitter//from w w w . j a v a 2s .c o m * @param retweetTo * @param retweeter * @param page * @return * @throws TwitterException */ private List<Status> loadRetweetersTweets(Twitter twitter, long retweetTo, long retweeter, int page) throws TwitterException { if (!alive) { return null; } if (page > timelinePages) { log.info(retweetTo + " retweet by " + retweeter + " ? " + (timelinePages * 100) + "????????????"); insertRetweeter(twitter.getId(), retweetTo, retweeter); return null; } Paging paging = new Paging(retweetTo); paging.setPage(page); paging.setCount(100); ResponseList<Status> userTimeline = gtUserTimeline(twitter, retweeter, paging); if (userTimeline.size() == 0) { return null; } List<Status> result = new ArrayList<Status>(); for (Status s : userTimeline) { result.add(s); if (s.isRetweet()) { if (s.getRetweetedStatus().getId() != retweetTo) { continue; } log.debug("found!!"); return result; } } return loadRetweetersTweets(twitter, retweetTo, retweeter, page + 1); }
From source file:org.apache.streams.twitter.provider.TwitterTimelineProviderTask.java
License:Apache License
@Override public void run() { Paging paging = new Paging(1, 200); List<Status> statuses = null; do {/*from w ww.j av a 2 s.c o m*/ int keepTrying = 0; // keep trying to load, give it 5 attempts. //This value was chosen because it seemed like a reasonable number of times //to retry capturing a timeline given the sorts of errors that could potentially //occur (network timeout/interruption, faulty client, etc.) while (keepTrying < 5) { try { this.client = provider.getTwitterClient(); statuses = client.getUserTimeline(id, paging); for (Status tStat : statuses) { String json = TwitterObjectFactory.getRawJSON(tStat); provider.addDatum(new StreamsDatum(json)); } paging.setPage(paging.getPage() + 1); keepTrying = 10; } catch (TwitterException twitterException) { keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException); } catch (Exception e) { keepTrying += TwitterErrorHandler.handleTwitterError(client, e); } } } while (provider.shouldContinuePulling(statuses)); LOGGER.info(id + " Thread Finished"); }
From source file:org.mariotaku.twidere.loader.UserRetweetedStatusLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; if (mStatusId > 0) { final Paging paging = new Paging(); paging.setCount(mLoadItemLimit); if (mPage > 0) { paging.setPage(mPage); }// w w w . j a v a 2 s. c o m final ResponseList<User> users = twitter.getRetweetedBy(mStatusId, paging); if (users == null) return null; final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); final int users_list_size = mUsersList.size(); final int size = users.size(); for (int i = 0; i < size; i++) { final User user = users.get(i); result.add(new ParcelableUser(user, getAccountId(), users_list_size + i)); } return result; } return null; }
From source file:org.tweetalib.android.TwitterPaging.java
License:Apache License
public Paging getT4JPaging() { Paging result = new Paging(); if (mMaxId == null && mSinceId == null) { if (mPage != null) { result.setPage(mPage); } else {//from ww w . j a va2s. c om result.setPage(1); } } else { if (mMaxId != null) { if (mMaxId.longValue() >= 0) { result.setMaxId(mMaxId); } else { Log.d("ERROR", "mMaxId is " + mMaxId.longValue() + ", must be >= 0"); } } if (mSinceId != null) { if (mSinceId.longValue() >= 0) { result.setSinceId(mSinceId); } else { Log.d("ERROR", "mSinceId is " + mSinceId.longValue() + ", must be >= 0"); } } } if (mCount != null) { result.setCount(mCount); } else { result.setCount(DEFAULT_STATUS_COUNT); } return result; }
From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java
public static void GetDirectMessage(Twitter twitter) throws ApiException, InterruptedException { //Twitter twitter = new TwitterFactory().getInstance(); try {/*from w ww.j a v a2 s .co m*/ Paging paging = new Paging(1); List<DirectMessage> messages; do { messages = twitter.getDirectMessages(paging); for (DirectMessage message : messages) { System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - " + message.getText()); user_name = user_name.concat(message.getSenderScreenName()); user_message = message.getText(); //send a tweet //Status status = twitter.updateStatus("Hola " +user_name +" Estamos atendiendo tu peticion! #Fintechando #HaciendoElParo"); DirectLineToBot(user_name, user_message); SendDirectMessageAsResponse(twitter); } paging.setPage(paging.getPage() + 1); } while (messages.size() > 0 && paging.getPage() < 10); /*System.out.println("done."); System.exit(0);*/ } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); } catch (ApiException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); } }