{"id":8018,"date":"2012-09-24T01:03:19","date_gmt":"2012-09-23T19:33:19","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8018"},"modified":"2017-11-22T16:09:35","modified_gmt":"2017-11-22T10:39:35","slug":"retweet-a-tweet-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/retweet-a-tweet-using-twitter4j\/","title":{"rendered":"Retweet a tweet using Twitter4j"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In one of my grails project, i worked on integrating twitter API with the grails application. The requirement is such that we need to display all of the tweets to any user in our application and provide the basic functionality such as reply, retweet, favorite, send direct message etc using the API calls. I used <a href=\"http:\/\/twitter4j.org\/en\/index.html\">Twitter4j<\/a> (a java wrapper for twitter API calls), to make API calls.<\/p>\n<pre><\/pre>\n<p>In the previous <a href=\"http:\/\/www.tothenew.com\/blog\/mark-tweet-as-favorite-using-twitter4j\/\">blog<\/a>, we saw how to mark any tweet as &#8216;Favorite&#8217; using Twitter4j. In this blog we will see how to <strong>Retweet<\/strong> any particular tweet using the same library<\/p>\n<pre><\/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><\/pre>\n<p><strong>Pre-Requirements:-<\/strong><\/p>\n<p>[java]<br \/>\n       String consumerKey = CONSUMER_KEY \/\/ key obtained after registering app.<br \/>\n       String consumerSecret =CONSUMER_SECRET \/\/ secret key obtained from the registered app.<br \/>\n       String twitterToken = USER_TWITTER_TOKEN<br \/>\n       \/\/ access_token received by authentication user&#8217;s twitter account<br \/>\n       String twitterSecret= USER_TWITTER_SECRET<br \/>\n        \/\/ access_secret obtained by authentication user&#8217;s twitter account<br \/>\n       Long tweetId = \/\/ messageId of the tweet to be retweeted<\/p>\n<p>[\/java]<\/p>\n<pre><\/pre>\n<p><strong>Code to Retweet a Tweet:-<\/strong><\/p>\n<p>[java]<\/p>\n<p>       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        twitter.retweetStatus(tweetId)<br \/>\n    }<br \/>\n[\/java]<\/p>\n<p>So, the above code will create a <strong>Retweet<\/strong> for that tweet.<br \/>\nThis worked for me.<br \/>\nHope it helps.<\/p>\n<pre><\/pre>\n<p>Other Blogs:-<\/p>\n<p><a href=\"http:\/\/www.tothenew.com\/blog\/sending-direct-message-to-a-twitter-user-using-twitter4j\/\">Send Direct Message using Twitter4j<\/a><br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/mark-tweet-as-favorite-using-twitter4j\/\">Mark Tweet as Favorite using Twitter4j<\/a><br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/reply-to-a-user-tweet-using-twitter4j\/\">Reply to a tweet using Twitter4j<\/a><br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/posting-status-update-on-twitter-using-twitter4j\/\">Post status update using Twitter4j<\/a><\/p>\n<pre><\/pre>\n<p>Cheers!!!<br \/>\nVishal Sahu<br \/>\nvishal@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In one of my grails project, i worked on integrating twitter API with the grails application. The requirement is such that we need to display all of the tweets to any user in our application and provide the basic functionality such as reply, retweet, favorite, send direct message etc using the API calls. I [&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":4},"categories":[7],"tags":[1024,700,873,1018,1022,1023,1025,1019],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8018"}],"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=8018"}],"version-history":[{"count":1,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8018\/revisions"}],"predecessor-version":[{"id":52477,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8018\/revisions\/52477"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}