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(); ...
Get Spring Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.