{"id":8722,"date":"2012-09-25T22:55:42","date_gmt":"2012-09-25T17:25:42","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8722"},"modified":"2012-09-25T22:55:42","modified_gmt":"2012-09-25T17:25:42","slug":"fetching-users-home-timeline-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/fetching-users-home-timeline-using-twitter4j\/","title":{"rendered":"Fetching User&#8217;s Home Timeline using Twitter4j"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In the previous <a href=\"http:\/\/www.tothenew.com\/blog\/posting-status-update-on-twitter-using-twitter4j\/\">blog<\/a> we saw how to post status update on Twitter using Twitter4j library.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>In the same project i had the requirement to show Twitter home timeline inside our application. I used the same java wrapper library to retrieve tweets from the user twitter account. In this blog we will see how to retrieve the Users Timeline using API calls.<\/p>\n<pre>\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 Twitter User Home Timeline :-<\/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)<\/p>\n<p>           int totalTweets = 20 \/\/ no of tweets to be fetched<br \/>\n           Paging paging = new Paging(1, totalTweets)<br \/>\n           List tweets = twitter.getHomeTimeline(paging)<\/p>\n<p>           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>So, this code will fetch the latest 20 tweets from the User Timeline 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 post status update on Twitter using Twitter4j library. In the same project i had the requirement to show Twitter home timeline inside our application. I used the same java wrapper library to retrieve tweets from the user twitter account. In this blog we will see how [&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":1},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8722"}],"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=8722"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8722\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}