{"id":8751,"date":"2012-09-25T23:16:40","date_gmt":"2012-09-25T17:46:40","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8751"},"modified":"2012-09-25T23:16:40","modified_gmt":"2012-09-25T17:46:40","slug":"get-tweets-posted-by-user-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/get-tweets-posted-by-user-using-twitter4j\/","title":{"rendered":"Get tweets posted by user using Twitter4j"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In the previous blog we saw how to fetch tweets in which a particular user is mentioned, using the Twitter4j java wrapper library available for Twitter API calls.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>In the same project, i had the requirement to display the tweets posted by particular user including retweets. I searched for it and found a cool way to achieve this using Twitter4j library.<\/p>\n<pre>\r\n\r\n\r\n<\/pre>\n<p>For making any twitter API calls we need to have twitter account <strong>access_token<\/strong> and <strong>access_secret<\/strong>, which we obtains after authorizing\/connecting twitter account with the application as mentioned in this <a href=\"http:\/\/www.tothenew.com\/blog\/integrating-java-application-with-twitter\/\">blog<\/a>.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p><strong>Code to fetch Tweets by user :-<\/strong><\/p>\n<p>[java]<br \/>\n  TwitterFactory factory = new TwitterFactory()<br \/>\n        Twitter twitter = factory.getInstance()<br \/>\n        twitter.setOAuthConsumer(consumerKey, consumerSecret)<br \/>\n        AccessToken accessToken = new AccessToken(twitterToken, twitterSecret)<br \/>\n        twitter.setOAuthAccessToken(accessToken)<br \/>\n            int totalTweets = page * 20<br \/>\n            Paging paging = new Paging(1, totalTweets)<br \/>\n            List tweets = twitter.getUserTimeline(paging)<br \/>\n            tweets.each {tweet -&gt;<br \/>\n                     println &quot;ID : ${tweet.id}&quot;<br \/>\n                     println &quot;User : ${tweet.user.screenName}&quot;<br \/>\n                     println &quot;Tweet : ${tweet.text}&quot;<br \/>\n         }<br \/>\n[\/java]<\/p>\n<p>This code will fetch the latest 20 tweets which user has posted using API calls.<\/p>\n<p>Hope this helps.<\/p>\n<pre>\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In the previous blog we saw how to fetch tweets in which a particular user is mentioned, using the Twitter4j java wrapper library available for Twitter API calls. In the same project, i had the requirement to display the tweets posted by particular user including retweets. I searched for it and found a cool [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8751"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8751"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8751\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}