Friends list of a friend using Twitter4J

How can I get friends list of friend or follower using Twitter4J ?

Using getFriendsId() , I can only get a list of friends / followers of this current authenticated user. I want to get a friend list of a follower or friend of an authenticated user.

+6
source share
7 answers
 long lCursor = -1; IDs friendsIDs = twitter.getFriendsIDs(userID, lCursor); System.out.println(twitter.showUser(userID).getName()); System.out.println("=========================="); do { for (long i : friendsIDs.getIDs()) { System.out.println("follower ID #" + i); System.out.println(twitter.showUser(i).getName()); } }while(friendsIDs.hasNext()); 
+2
source

This will show the name of your follower friends.

  User u1 = null ; long cursor = -1; IDs ids; System.out.println("Listing followers ids."); do { ids = twitter.getFollowersIDs("username", cursor); for (long id : ids.getIDs()) { System.out.println(id); User user = twitter.showUser(id); System.out.println(user.getName()); } } while ((cursor = ids.getNextCursor()) != 0); 
+6
source

You only need to do this:

 Twitter twitter = mTwitterApp.getTwitterInstance(); long cursor = -1; List<User> users=twitter.getFriendsList(mTwitterApp.getUserID(), cursor); 

Here, users is a list of users who are your friends (you follow them). mTwitterApp.getUserID () is your username, which is a long value.

+3
source
  PagableResponseList<User> friendlist= twitter.getFriendsList(user.getScreenName(), -1); int sizeoffreindlist= friendlist.size(); for(int i=0;i<sizeoffreindlist;i++) { System.out.println(friendlist.get(i)); } 

It will give you a list of 20 friends, since the default limit is 20

+1
source

How about getting a friends list? https://dev.twitter.com/docs/api/1.1/get/friends/list

According to the docs:

Returns a programmed collection of user objects for each user. the user listed below (otherwise known as their "friends").

Twitter4j.api has an interface for this, but I cannot figure out how to use it:

 PagableResponseList<User> getFriendsList(String screenName, long cursor) throws TwitterException; 
0
source

This code works! (without exceeding speed limits). Link documentation twitter4j and other answers to StackOverflow.

  try { // get friends long cursor = -1; PagableResponseList<User> pagableFollowings; do { pagableFollowings = twitter.getFriendsList(twitter.getId(), cursor); for (User user : pagableFollowings) { listFriends.add(user); // ArrayList<User> } } while ((cursor = pagableFollowings.getNextCursor()) != 0); // get followers cursor = -1; PagableResponseList<User> pagableFollowers; do { pagableFollowers = twitter.getFollowersList(twitter.getId(), cursor); for (User user : pagableFollowers) { listFollowers.add(user); // ArrayList<User> } } while ((cursor = pagableFollowers.getNextCursor()) != 0); } catch (TwitterException e) { printError(e); } 
0
source

you can use

 twitter.getFollowersIDs("username", cursor); 

http://twitter4j.org/javadoc/twitter4j/api/FriendsFollowersResources.html#getFollowersIDs-java.lang.String-long- which returns only 5,000 users, not all users. It is also limited 15 times in 15 minutes. ( https://dev.twitter.com/rest/reference/get/friends/ids )

Alternatively, you can use

 twitter.getFollowersList("username", cursor); 

http://twitter4j.org/javadoc/twitter4j/api/FriendsFollowersResources.html#getFollowersList-java.lang.String-long- , which is also limited to 20 users. It is also limited 15 times in 15 minutes for the auth user, 30 times in 15 minutes for the auth application ( https://dev.twitter.com/rest/reference/get/friends/list )

For unlimited access, you can look at https://gnip.com/ or get access to a user with user rights in the white list.

0
source

Source: https://habr.com/ru/post/906186/


All Articles