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:
- In the
TwitterController
class, add aModel
argument to thetw()
method:@RequestMapping("/fw") public String fb(HttpServletRequest request, Model model) { ...
- In that method, use the Twitter object to retrieve the user's tweets:
List<Tweet> tweets = twitter.timelineOperations().getUserTimeline();
- Pass the list of tweets to the JSP view:
model.addAttribute("tweets", tweets);
- In the JSP, display the list of tweets:
<c:forEach items="${tweets}" var="tweet"> <p>${tweet.text}</p> </c:forEach>