In one of my grails project, i worked on integrating twitter API with the application. The requirement is such that we need to display all of the tweets to any user and provide the basic functionality such as reply, retweet, favorite etc using the API calls. I used Twitter4j (a java wrapper for twitter API calls), to make API calls. You can refer this blog to see how we can integrate the grails application with Twitter.
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 Long tweetId = // id of the tweet
Code to mark tweet as Favorite:-
TwitterFactory factory = new TwitterFactory() Twitter twitter = factory.getInstance() twitter.setOAuthConsumer(consumerKey, consumerSecret) AccessToken accessToken = new AccessToken(twitterToken, twitterSecret) twitter.setOAuthAccessToken(accessToken) Status status = twitter.createFavorite(tweetId)
The above code will mark the tweet as ‘Favorite’ for that user.
This worked for me.
Hope it helps.