Retrieving the list of friends of a Facebook user
In this recipe, you'll learn how to retrieve the friends list of a Facebook user from a Spring web application.
Getting ready
This recipe uses the code from the Connecting to Facebook recipe.
How to do it…
Here are the steps to retrieve the list of friends of a Facebook user:
- In the
FacebookController
class, in thelogin()
method, adduser_friends
to thescope
parameter:params.setScope("public_profile, user_friends");
- Add a
Model
argument to thefb()
method:@RequestMapping("/fb") public String fb(HttpServletRequest request, Model model) { ...
- In the
if(facebook.isAuthorized())
block, use the Facebook object to get the list of friends:List<Reference> friendList = facebook.friendOperations().getFriends();
- Retrieve the profile of each friend:
List<FacebookProfile> friendProfileList = new LinkedList<FacebookProfile>(); for (Reference friend : friendList) { FacebookProfile friendProfile = facebook...