Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

    @RequestMapping("/fb")
    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: ${profile.id}<br />
    username: ${profile.username}<br />
    name: ${profile.name}<br />
    gender: ${profile.gender}<br />
    email: ${profile.email}<br />
    birthday: ${profile.birthday...