Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Friends list of a friend using Twitter4J

Tags:

java

twitter4j

How can I obtain the friends list of a friend or follower using Twitter4J?

Using getFriendsId(), I'm only able to retrieve the friend's/follower's list of that current user which is authenticated. What I want is to obtain the list of friends of a follower or friend of the authenticated user.

like image 852
sandeepsharat Avatar asked Jan 17 '12 09:01

sandeepsharat


2 Answers

This will show the name of your friend's followers.

      User u1 = null ;
      long cursor = -1;
      IDs ids;
      System.out.println("Listing followers's 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);
like image 151
vikiiii Avatar answered Oct 23 '22 17:10

vikiiii


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 users who are your friends(you are following them). mTwitterApp.getUserID() is your login useris which is a long value.

like image 25
Mohit Verma Avatar answered Oct 23 '22 17:10

Mohit Verma