Twitter4j gets followers with the most followers

Im using twitter 4j for a small twitter application and im currently using the following code to get follower IDs that I need for the user (let ME say), I like to have the top 10 users who have the most followers (following code gets user profile identifiers). I got 80 followers on my Twitter profile and I like to get followers who have more followers (first 10)

Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET); String accessToken = getSavedAccessToken(); String accessTokenSecret = getSavedAccessTokenSecret(); AccessToken oathAccessToken = new AccessToken(accessToken, accessTokenSecret); twitter.setOAuthAccessToken(oathAccessToken); User user = null; try { user = twitter.showUser(username);// id = user.getId(); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
+4
source share
1 answer

To get followers of a given user using their screen name, see Twitter#getFollowersList() , for example:

 long cursor = -1; PagableResponseList<User> followers; do { followers = twitter.getFollowersList("screenName", cursor); for (User follower : followers) { // TODO: Collect top 10 followers here System.out.println(follower.getName() + " has " + follower.getFollowersCount() + " follower(s)"); } } while ((cursor = followers.getNextCursor()) != 0); 

I used the cursor to retrieve all subscribers, by default the api call returns only twenty - see the Twitter guide on Using cursors for navigation for more information.

Inside the loop, you can collect your β€œtop 10” followers by checking the follow-up count.

+4
source

All Articles