List of usage examples for twitter4j PagableResponseList getNextCursor
@Override
long getNextCursor();
From source file:com.klinker.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getFollowing(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;// w ww .j av a2 s . co m new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); PagableResponseList<User> friendsPaging; try { friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing); } catch (OutOfMemoryError e) { return; } for (int i = 0; i < friendsPaging.size(); i++) { following.add(friendsPaging.get(i)); Log.v("friends_list", friendsPaging.get(i).getName()); } if (friendsPaging.size() > 17) { hasMore = true; } else { hasMore = false; } currentFollowing = friendsPaging.getNextCursor(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (followingAdapter == null) { followingAdapter = new PeopleArrayAdapter(context, following); listView.setAdapter(followingAdapter); } else { followingAdapter.notifyDataSetChanged(); } if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); canRefresh = true; spinner.setVisibility(View.GONE); } }); } catch (Exception e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { if (user != null && user.isProtected()) { Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); } else { Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show(); } spinner.setVisibility(View.GONE); } catch (Exception e) { // fragment not attached } canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:com.marpies.ane.twitter.utils.UserUtils.java
License:Apache License
/** * Creates JSON from given response list and dispatches generic event. * Helper method for queries like getFollowers and getFriends. * @param users/*from w w w. j a v a 2 s . com*/ * @param callbackID */ public static void dispatchUsers(PagableResponseList<User> users, final int callbackID) { try { AIR.log("Got response with " + users.size() + " users"); /* Create array of JSON users */ JSONArray usersJSON = new JSONArray(); for (User user : users) { /* Create JSON for each user and put it to the array */ JSONObject userJSON = getJSON(user); usersJSON.put(userJSON.toString()); } JSONObject result = new JSONObject(); result.put("users", usersJSON); if (users.hasNext()) { result.put("nextCursor", users.getNextCursor()); } if (users.hasPrevious()) { result.put("previousCursor", users.getPreviousCursor()); } result.put("listenerID", callbackID); AIR.dispatchEvent(AIRTwitterEvent.USERS_QUERY_SUCCESS, result.toString()); } catch (JSONException e) { AIR.dispatchEvent(AIRTwitterEvent.USERS_QUERY_ERROR, StringUtils.getEventErrorJSON(callbackID, "Error creating result JSON: " + e.getMessage())); } }
From source file:com.zisal.twit.crawl.core.Example.java
public static void main(String[] args) { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(ApplicationConstant.TwitterKey.CUSTOMER_KEY, ApplicationConstant.TwitterKey.CUSTOMER_SECRET); twitter.setOAuthAccessToken(/*from w w w . j a v a2 s . c o m*/ new AccessToken(ApplicationConstant.TwitterKey.TOKEN, ApplicationConstant.TwitterKey.TOKEN_SECRET)); /*try{ ResponseList<Status> responseList = twitter.getUserTimeline(new Paging(1, 5)); for(Status s: responseList){ System.out.println("Response List ".concat(s.getText())); } }catch(Exception e){ e.printStackTrace(); } long cursor = -1; IDs ids = null; System.out.println("Listing followers's ids."); do { try { ids = twitter.getFollowersIDs(ApplicationConstant.Twitter.SCREEN_NAME, cursor); for (long id : ids.getIDs()) { System.out.println(id); User user = twitter.showUser(id); System.out.println(user.getName()); } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = ids != null ? ids.getNextCursor() : 0) != 0);*/ long cursor = -1; PagableResponseList<User> pagableFollowings = null; List<User> listFriends = new ArrayList<>(); do { try { pagableFollowings = twitter.getFriendsList(18211861, cursor); for (User user : pagableFollowings) { listFriends.add(user); logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend #1st level " + user.getName()); /*PagableResponseList<User> _2ndLevelPageableFollowings = twitter.getFriendsList(user.getId(), cursor); for(User _2ndLevelFriend : _2ndLevelPageableFollowings){ logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "added friend #2nd level "+ _2ndLevelFriend.getName()); listFriends.add(_2ndLevelFriend); }*/ } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = pagableFollowings.getNextCursor()) != 0); logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend total : " + listFriends.size()); for (User user : listFriends) { logger.info(ApplicationConstant.LogTag.ZUNA_INFO, "friend : " + user.getName()); } /* cursor = -1; PagableResponseList<User> pagableFollowers = null; List<User> listFollowers = new ArrayList<>(); do { try { pagableFollowers = twitter.getFollowersList(twitter.getId(), cursor); for (User user : pagableFollowers) { listFollowers.add(user); // ArrayList<User> System.out.println(user.getName()); } } catch (TwitterException e) { e.printStackTrace(); } } while ((cursor = pagableFollowers.getNextCursor()) != 0); */ }
From source file:d3V.GetFriendsIDs.java
License:Apache License
/** * Usage: java twitter4j.examples.friendsandfollowers.GetFollowersIDs [screen name] * * @param args message/*from w ww . j av a 2s. com*/ */ public static void main(String[] args) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Em3WTI7jc90HcvKzPkTLQ") .setOAuthConsumerSecret("vg4p6rOF32bmffqRR8m0jAUClrxvtGiMB5PrSr3Zsw") .setOAuthAccessToken("1681973072-1q0zI0VPjHD3ttNuaBOL94frzCI9sXInxAcDK0w") .setOAuthAccessTokenSecret("ZRLkOyjmhHBkU1iNyEVNyIgIBsKrl0DUDKOcOMneYFYEM"); cb.setJSONStoreEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); try { String core_user = "nytimes"; FileWriter writer = new FileWriter(core_user + "_friends.txt", true); Twitter twitter = tf.getInstance(); long cursor = -1; ArrayList<String> directFriends = new ArrayList<String>(); PagableResponseList<User> tempFriends = null; System.out.println("Listing " + core_user + " friends's ScreenNames."); int count = 0; //boolean first = true; //getFriends(writer, twitter, cursor, count, core_user); do { tempFriends = twitter.getFriendsList(core_user, cursor); for (User user : tempFriends) { directFriends.add(user.getScreenName()); writer.write(core_user + "\t" + user.getScreenName() + "\n"); } count += tempFriends.size(); System.out.println(core_user + ": " + count); if (count >= 100) break; Thread.sleep(300 * MILLISECOND); } while ((cursor = tempFriends.getNextCursor()) != 0); System.out.println("Size of DFs: " + directFriends.size()); // for (String user : directFriends){ for (int i = 0; i < directFriends.size(); i++) { // PagableResponseList<User> idrfriends = null; long _cursor = -1; int _count = 0; String _username = directFriends.get(i); System.out.println("\nFriends of Direct friend: " + _username + "(" + (i + 1) + ")"); try { getFriends(writer, twitter, _cursor, _count, _username); } catch (TwitterException e) { e.printStackTrace(); System.out.println("Failed to get friends' ids: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } writer.close(); System.out.println(count); System.exit(0); } catch (TwitterException e) { e.printStackTrace(); System.out.println("Failed to get friends' ids: " + e.getMessage()); System.exit(-1); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:d3V.GetFriendsIDs.java
License:Apache License
public static void getFriends(FileWriter writer, Twitter twitter, long _cursor, int _count, String _username) throws TwitterException, IOException, InterruptedException { PagableResponseList<User> idrfriends; do {/*from w w w. ja v a 2 s . co m*/ idrfriends = twitter.getFriendsList(_username, _cursor); for (User _user : idrfriends) { writer.write(_username + "\t" + _user.getScreenName() + "\n"); } _count += idrfriends.size(); System.out.println(_username + ": " + _count); if (_count >= 40) break; Thread.sleep(300 * MILLISECOND); } while ((_cursor = idrfriends.getNextCursor()) != 0); }
From source file:DataCollections.FriendsnFollowersCollection.java
public ArrayList<User_dbo> collectfriendsfollowersofuser(User_dbo cuserdbo) throws InterruptedException { long cursor = -1; PagableResponseList<User> list; User user;/*from w w w. j a va2s. c om*/ User_dbo userdbo; ArrayList<User_dbo> userdbolist = new ArrayList<>(); boolean available = true; Logger.LogPrinter.printLog( "Retrieving friends of the user " + cuserdbo.values[User_dbo.map.get("screename")].string); while (available) { try { list = ffresources.getFriendsList(cuserdbo.values[User_dbo.map.get("user_id")].lnumber, cursor); ListIterator li = list.listIterator(); while (li.hasNext()) { user = (User) li.next(); LogPrinter.printLog("" + user.getName()); userdbo = userhelper.convertUserToUser_dbo(user); userdbolist.add(userdbo); //LogPrinter.printLog(" Friend retrieved"+userdbo.values[User_dbo.map.get("screename")].string); } if (list.hasNext()) { cursor = list.getNextCursor(); } else { available = false; } } catch (Exception e) { e.printStackTrace(); Logger.LogPrinter.printLog(" Sleeping... rate limit exceeded will try after " + 900 * 1000); Thread.sleep(900 * 1000 + 500); LogPrinter.printLog(" Message " + e.getMessage()); } } LogPrinter.printLog("No of friends retrieved: " + userdbolist.size()); available = true; cursor = 0; Logger.LogPrinter.printLog( "Retrieving followers of the user " + cuserdbo.values[User_dbo.map.get("screename")].string); while (available) { try { list = ffresources.getFollowersList(cuserdbo.values[User_dbo.map.get("user_id")].lnumber, cursor); ListIterator li = list.listIterator(); while (li.hasNext()) { user = (User) li.next(); userdbo = userhelper.convertUserToUser_dbo(user); userdbolist.add(userdbo); } if (list.hasNext()) { cursor = list.getNextCursor(); } else { available = false; } } catch (Exception e) { Logger.LogPrinter.printLog(" Sleeping... rate limit exceeded will try after " + 900 * 1000); Thread.sleep(900 * 1000 + 500); LogPrinter.printLog(" Message " + e.getMessage()); } } LogPrinter.printLog("No of friends/follwers retrieved: " + userdbolist.size()); return userdbolist; }
From source file:examples.GetFriendsIDs.java
License:Apache License
/** * Usage: java twitter4j.examples.friendsandfollowers.GetFriendsIDs [screen name] * * @param args message/*from ww w .ja v a 2s .co m*/ */ public static void main(String[] args) { try { Twitter twitter = CommonUtils.getTwitterInstance(); long cursor = -1; PagableResponseList<User> userList; System.out.println("Listing following ids."); do { userList = twitter.getFriendsList("tsantoo", cursor); for (User user : userList) { System.out.println(user.toString()); } } while ((cursor = userList.getNextCursor()) != 0); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get friends' ids: " + te.getMessage()); System.exit(-1); } }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@GET @Path("/friends/{id}") @Produces(MediaType.TEXT_PLAIN)//from w ww. j a v a 2 s .c o m public String getFriends(@PathParam("id") String id) { String result = ""; long cursor = -1; PagableResponseList<User> list_l; try { do { list_l = link.getFriendsList(id, cursor); for (User user_l : list_l) { result += user_l.getName() + "\n"; } } while ((cursor = list_l.getNextCursor()) != 0); } catch (TwitterException e) { logger.error(e.getMessage(), e); } return result; }
From source file:fr.istic.taa.jaxrs.TweetEndpoint.java
License:Apache License
@GET @Path("/followers/{id}") @Produces(MediaType.TEXT_PLAIN)//from w w w . ja v a 2s .co m public String getFollowers(@PathParam("id") String id) { String result = ""; long cursor = -1; PagableResponseList<User> list_l; try { do { list_l = link.getFollowersList(id, cursor); for (User user_l : list_l) { result += user_l.getName() + "\n"; } } while ((cursor = list_l.getNextCursor()) != 0); } catch (TwitterException e) { logger.error(e.getMessage(), e); } return result; }
From source file:info.maslowis.twitterripper.command.impl.twitter.FriendDeleteAll.java
License:Open Source License
@Override public void execute() throws ExecuteCmdException { try {//www.j a v a 2s. c o m out.println(ansi().a(Attribute.INTENSITY_BOLD).fg(Color.RED) .a("This command delete all user from your friend list! You want to continue? [yes/no]") .reset()); String input = Application.INSTANCE.getReader().readLine(); if (input.trim().equalsIgnoreCase("yes")) { try { long nextCursor = -1L; final int countEntry = 200; while (nextCursor != 0) { PagableResponseList<User> users = twitter.getFriendsList(twitter.getId(), nextCursor, countEntry); for (User user : users) { twitter.friendsFollowers().destroyFriendship(user.getId()); out.println("You unfollow from " + Util.toString(user)); } nextCursor = users.getNextCursor(); } } catch (TwitterException e) { throw new ExecuteCmdException(e); } } else { out.println("Command was cancelled"); } } catch (IOException e) { logger.error("Error reading input", e); exit(-1); } }