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 user's Twitter profile


In this recipe, you'll learn how to retrieve a user's Twitter profile data, which automatically becomes available to the Twitter application once the user has authorized the Twitter application.

Getting ready

This recipe uses the code from the Connecting to Twitter recipe.

How to do it…

Here are the steps to retrieve data from the profile of a Twitter user:

  1. In the TwitterController class, add a Model argument to the tw() method:

    @RequestMapping("/fw")
    public String fb(HttpServletRequest request, Model model) {
    ...
  2. In that method, use the Twitter object to retrieve the user profile:

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

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

    name: ${profile.name}<br />
    screenName: ${profile.screenName}<br />
    url: ${profile.url}<br />
    profileImageUrl: ${profile.profileImageUrl}<br />
    description: ${profile.description...