In this recipe, you'll learn how to retrieve the last tweets of a Twitter user from a Spring web application.
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>