collect: while (cursor != 0) { try { IDs ids = networkRelation == Networker.FOLLOWERS ? twitter.getFollowersIDs(screen_name, cursor) : twitter.getFriendsIDs(screen_name, cursor); RateLimitStatus rateStatus = ids.getRateLimitStatus(); if (networkRelation == Networker.FOLLOWERS) {
/** * Returns an array of numeric IDs for every user the specified user is followed by. * @param userId Specfies the ID of the user for whom to return the followers list. * @return The ID or screen_name of the user to retrieve the friends ID list for. * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.0 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids">Twitter API Wiki / Twitter REST API Method: followers ids</a> */ public IDs getFollowersIDs(int userId) throws TwitterException { return getFollowersIDs(userId, -1l); }
/** * Returns an array of numeric IDs for every user the specified user is followed by. * @return The ID or screen_name of the user to retrieve the friends ID list for. * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.0 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids">Twitter API Wiki / Twitter REST API Method: followers ids</a> */ public IDs getFollowersIDs() throws TwitterException { return getFollowersIDs(-1l); }
/** * Returns an array of numeric IDs for every user the specified user is followed by. * @param screenName Specfies the screen name of the user for whom to return the followers list. * @return The ID or screen_name of the user to retrieve the friends ID list for. * @throws TwitterException when Twitter service or network is unavailable * @since Twitter4J 2.0.0 * @see <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids">Twitter API Wiki / Twitter REST API Method: followers ids</a> */ public IDs getFollowersIDs(String screenName) throws TwitterException { return getFollowersIDs(screenName, -1l); }
Twitter myTwitter = new TwitterFactory().getInstance(); long[] followerIds = myTwitter.getFollowersIDs("screenName", -1).getIDs();
@Override public void invoke(List<TwitterListener> listeners) throws TwitterException { IDs ids = twitter.getFollowersIDs(cursor); for (TwitterListener listener : listeners) { try { listener.gotFollowersIDs(ids); } catch (Exception e) { logger.warn("Exception at getFollowersIDs", e); } } } });
@Override public void invoke(List<TwitterListener> listeners) throws TwitterException { IDs ids = twitter.getFollowersIDs(screenName, cursor); for (TwitterListener listener : listeners) { try { listener.gotFollowersIDs(ids); } catch (Exception e) { logger.warn("Exception at getFollowersIDs", e); } } } });
@Override public void invoke(List<TwitterListener> listeners) throws TwitterException { IDs ids = twitter.getFollowersIDs(userId, cursor); for (TwitterListener listener : listeners) { try { listener.gotFollowersIDs(ids); } catch (Exception e) { logger.warn("Exception at getFollowersIDs", e); } } } });
try { Twitter twitter = new TwitterFactory().getInstance(); long cursor = -1; IDs ids; System.out.println("Listing followers's ids."); do { if (0 < userId) { ids = twitter.getFollowersIDs(userId, cursor); } else { ids = twitter.getFollowersIDs(cursor); } for (long id : ids.getIDs()) { System.out.println(id); } } while ((cursor = ids.getNextCursor()) != 0); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get followers' ids: " + te.getMessage()); System.exit(-1); }
TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); String twitterScreenName; try { twitterScreenName = twitter.getScreenName(); IDs followerIDs = twitter.getFollowersIDs(twitterScreenName, -1); long[] ids = followerIDs.getIDs(); for (long id : ids) { twitter4j.User user = twitter.showUser(id); //here i am trying to fetch the followers of each id String userScreenName = user.getScreenName(); System.out.println("Name: " + user.getScreenName()); System.out.println("Location:" + user.getLocation()); IDs followerIDsOfFollowers = twitter.getFollowersIDs(user.getScreenName(), -1); long[]fofIDs = followerIDsOfFollowers.getIDs(); for(long subId : fofIDs) { twitter4j.User user1 = twitter.showUser(subId); System.out.println("Follower Master:" + userScreenName +" Follower of Follower Name: " + user1.getScreenName()); System.out.println("Location:" + user1.getLocation()); }
@Override public Set<Long> getFollowers(final Long userId, final Optional<Principal> principal) throws WTFDYUMException { Preconditions.checkNotNull(userId); final Twitter twitter = principal.isPresent() ? twitter(principal.get()) : twitter(); final Set<Long> result = new HashSet<>(); try { IDs followersIDs = null; long cursor = -1; do { followersIDs = twitter.getFollowersIDs(userId, cursor); if(followersIDs.hasNext()) { cursor = followersIDs.getNextCursor(); checkRateLimitStatus(followersIDs.getRateLimitStatus(), WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED); } final Set<Long> currentFollowers = Arrays.stream(followersIDs.getIDs()).boxed() .collect(Collectors.toCollection(() -> new HashSet<>())); result.addAll(currentFollowers); } while (followersIDs.hasNext()); } catch (final TwitterException e) { log.debug("Error while getFollowers", e); throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR); } return result; }
System.out.println("Listing followers's ids."); do { ids = twitter.getFollowersIDs("SrBachchan", cursor); for (long id : ids.getIDs()) { System.out.println(id);