/** * フォロー/アンフォロー処理を実行します。 * * @param twitter * @param mode * @param targetList */ public static void doProcessIds(Twitter twitter, int mode, List<Long> targetList) { if (targetList.size() > 0) { if (mode == DOREMOVE && 1000 <= targetList.size()) { log.info("アンフォロー件数が1000を超えているため、中止します。 removeSize:" + targetList.size() + "]"); return; } for (int i = 0; i < targetList.size(); i++) { long id = targetList.get(i); if (id <= 0) { continue; } try { if (mode == DOREMOVE) { twitter.destroyFriendship(id); log.info("remove: " + id); } else if (mode == DOFOLLOW) { twitter.createFriendship(id); log.info("follow: " + id); } } catch (TwitterException e) { log.info(e.getMessage()); } } } }
/** Remove all user's friendships (ie. people you are following). Note: Not time aware. */ private void removeFriendships() { try { long cursor = -1; IDs ids; do { ids = twitter.getFriendsIDs(cursor); for (long id : ids.getIDs()) { twitter.destroyFriendship(id); } } while ((cursor = ids.getNextCursor()) != 0); } catch (TwitterException e) { logger.error("Twitter exception occurred", e); } }