Book Image


Book Image


Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
About the Author
About the Reviewers

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:

  1. In the FacebookController class, add a Model argument to the fb() method:

    public String fb(HttpServletRequest request, Model model) {
  2. In the if(facebook.isAuthorized()) block, use the Facebook object to retrieve the user's profile:

    FacebookProfile profile = facebook.userOperations().getUserProfile(); 
  3. Pass the user profile to the JSP view:

    model.addAttribute("profile", profile); 
  4. In the JSP, display data from the user's profile:

    id: ${}<br />
    username: ${profile.username}<br />
    name: ${}<br />
    gender: ${profile.gender}<br />
    email: ${}<br />
    birthday: ${profile.birthday...