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); ...

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.