Twitter4j Grails Plugin
Dependency :
compile ":twitter4j:0.3.2"
Summary
Installation
grails install-plugin twitter4j
Description
This plugin makes it easy to both send and receive Twitter messages inside a Grails application.And before your twitter-calls do this
Installation
grails install-plugin twitter4j
Configuration
Enable your application in twitter.
Log into your twitter account (eg. http://www.twitter.com/yourname) and then go to https://dev.twitter.com/apps/new to register your app.Select your application type as "Client"Make a note of your Consumer Key and Consumer Secret, you will need it shortlyGetting your requestToken from Twitter
run your app, and goto http://localhost:8080/yourApp/twitter4j- enter the Consumer Key and Secret and click "Request token"Click the link on the next screen, and follow the instructions to obtain your PIN. Enter the pin-code and click "Verify pin"Paste the configuration code into your Config.groovy file and restart the appTest if it works
Goto http://localhost:8080/yourApp/twitter4j/status and enter a twitter-message. If it works, you should be able to see your update on your twitter page: http://www.twitter.com/yournameExamples
The following are some simple examples to give you a feel for the plugin.Sending a twitter update
In a controller or serviceclass SomeController { def twitter4jService def someAction = {
twitter4jService.updateStatus("This is a status-update from twitter")
}
}Getting your own latest updates
class SomeController { def twitter4jService def someAction = {
def updates = twitter4jService.getUserTimeline() // of type ResponseList<Status>
[statusUpdates: updates]
}
}More than one twitter-account?
Alter your configuration to:twitter {
disableTwitter4jController = true
'default' {
OAuthConsumerKey = '******'
OAuthConsumerSecret = '************'
OAuthAccessToken = '************'
OAuthAccessTokenSecret = '************'
}
'otherAccount' {
OAuthConsumerKey = '******'
OAuthConsumerSecret = '************'
OAuthAccessToken = '************'
OAuthAccessTokenSecret = '************'
}
}twitter4j.connect('otherAccount')