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 Twitter4j (a java wrapper for twitter API calls), to make API calls.
In the previous blog, we saw how to send ‘Direct Message’ to any twitter user using Twitter4j. In this blog we will see how to replay to any particular tweet using the same library
For making any twitter API calls we need to have twitter account access_token and access_secret, which we obtains after authorizing/connecting twitter account with the application as mentioned in this blog.
String consumerKey = CONSUMER_KEY // key obtained after registering app.
String consumerSecret =CONSUMER_SECRET // secret key obtained from the registered app.
String twitterToken = USER_TWITTER_TOKEN
// access_token received by authentication user’s twitter account
String twitterSecret= USER_TWITTER_SECRET
// access_secret obtained by authentication user’s twitter account
String replyMessage=’Hi, this is just a test message.’
Long inReplyToStatusId = // messageId of the tweet to which the user is replying
Code to Reply to Twitter User:-
TwitterFactory factory = new TwitterFactory()
Twitter twitter = factory.getInstance()
AccessToken accessToken = new AccessToken(twitterToken, twitterSecret)
StatusUpdate statusUpdate = new StatusUpdate(replyMessage)
statusUpdate.inReplyToStatusId = inReplyToStatusId
Status status = twitter.updateStatus(statusUpdate)
So, the above code will send a Reply tweet to the twitter .
This worked for me.
Hope it helps.