Book Image


Book Image


Overview of this book

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

Retrieving the tweets of a Twitter user

In this recipe, you'll learn how to retrieve the last tweets of a Twitter user from a Spring web application.

Getting ready

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

How to do it…

Here are the steps to retrieve the last tweets of a Twitter user:

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

    public String fb(HttpServletRequest request, Model model) {
  2. In that method, use the Twitter object to retrieve the user's tweets:

    List<Tweet> tweets = twitter.timelineOperations().getUserTimeline();
  3. Pass the list of tweets to the JSP view:

    model.addAttribute("tweets", tweets);
  4. In the JSP, display the list of tweets:

    <c:forEach items="${tweets}" var="tweet">