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());
    myFacebookFriendList.add(friend.getName());
  }
  System.out.println("All Friends : "+myFacebookFriendList);
}




Popular posts from this blog

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

Upload file on Google cloud storage using Java servlet on google app engine

Android: where to run keytool command in android