{"id":8010,"date":"2012-09-24T01:00:39","date_gmt":"2012-09-23T19:30:39","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8010"},"modified":"2015-05-19T17:44:23","modified_gmt":"2015-05-19T12:14:23","slug":"reply-to-a-user-tweet-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/reply-to-a-user-tweet-using-twitter4j\/","title":{"rendered":"Reply to a user 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\/sending-direct-message-to-a-twitter-user-using-twitter4j\/\">blog<\/a>, we saw how to send &#8216;Direct Message&#8217; to any twitter user using Twitter4j. In this blog we will see how to replay to 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       String replyMessage=&#8217;Hi, this is just a test message.&#8217;<br \/>\n       Long inReplyToStatusId = \/\/ messageId of the tweet to which the user is replying<\/p>\n<p>[\/java]<\/p>\n<pre><\/pre>\n<p><strong>Code to Reply to Twitter User:-<\/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        StatusUpdate statusUpdate = new StatusUpdate(replyMessage)<br \/>\n        statusUpdate.inReplyToStatusId = inReplyToStatusId<br \/>\n        Status status = twitter.updateStatus(statusUpdate)<br \/>\n    }<br \/>\n[\/java]<\/p>\n<p>So, the above code will send a <strong>Reply<\/strong> tweet to the twitter .<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\/retweet-a-tweet-using-twitter4j\/\">Retweet 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":[706,700,882,873,1018,1022,1026,1019],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8010"}],"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=8010"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8010\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}