Retrieving a Facebook user's profile
In this recipe, you'll learn how to retrieve a Facebook user's profile data, which automatically becomes available to the app once the user has authorized it.
Getting ready
This recipe uses the code from the Connecting to Facebook recipe.
How to do it…
Here are the steps to retrieve the profile of a Facebook user:
- In the
FacebookController
class, 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 retrieve the user's profile:FacebookProfile profile = facebook.userOperations().getUserProfile();
- Pass the user profile to the JSP view:
model.addAttribute("profile", profile); ...
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.