Twitter4j Grails Plugin

  • Tags : twitter
  • Latest : 0.3.2
  • Last Updated: 29 January 2012
  • Grails version : 1.3.7 > *
  • Authors : sbglasius, arthurnn
3 votes
Dependency :
compile ":twitter4j:0.3.2"

Documentation Source

Summary

Installation

grails install-plugin twitter4j

Description

This plugin makes it easy to both send and receive Twitter messages inside a Grails application.

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 shortly

Getting 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 app

Test 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/yourname

Examples

The following are some simple examples to give you a feel for the plugin.

Sending a twitter update

In a controller or service

class 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 = '************'
    }
}

And before your twitter-calls do this

twitter4j.connect('otherAccount')

Where to get more information.

The plugin exposes the Twitterj4 API through @Delegation.

Find the Twitter4j homepage here: http://twitter4j.org