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);
}
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);
}
This is only for friend's name, how would we fetch their email ids...
ReplyDeleteFacebook do not allow (at the moment) to access friends emails.
ReplyDeleteRef: https://developers.facebook.com/docs/reference/api/permissions/
I want to generate a graph of friends in my friedlist, so is it possible to get the friendlist of those friends also.
ReplyDeleteThank you very much!
ReplyDelete