get facebook friends using restfb

If you are using restfb (Facebook graph API and old REST API client wriiten in Java), and you want to access all friend list after Oauth authentication, you can use following method,

public List<ArrayList> findFacebookFriendsUsingRest(String facebookAccessToken){
  List<ArrayList> myFacebookFriendList= new ArrayList();
  final FacebookClient facebookClient;
  facebookClient = new DefaultFacebookClient(facebookAccessToken);
  User user = facebookClient.fetchObject("me", User.class);
  String userName = user.getFirstName();
  if (userName == null){
  userName = user.getLastName();
  String userEmail = user.getEmail();
  com.restfb.Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);
  System.out.println("Count of my friends: " + myFriends.getData().size());
  for(User friend: myFriends.getData()){
  System.out.println("Friends id and name: "+friend.getId()+" , "+friend.getName());
  System.out.println("All Friends : "+myFacebookFriendList);


  1. This is only for friend's name, how would we fetch their email ids...

  2. Facebook do not allow (at the moment) to access friends emails.


  3. I want to generate a graph of friends in my friedlist, so is it possible to get the friendlist of those friends also.

  4. Thank you very much!


Post a Comment

Popular posts from this blog

Struts 2 - struts tag with boolean property

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.