Saturday, August 15, 2009

Twitter through Grails Application

Doing twitter is very easy in grails application.

Here is a barebone twitter service code. Simply put it into your grails-app/services directory

import twitter4j.Twitter

class TwitterService {
boolean transactional = false
def update(String message) {
Twitter twitter = new Twitter("username", "password");
twitter.updateStatus(message);
}
}

Notice the twitter4j package is used here

In your controller or job, define the service
def twitterService

whereever you want to update your twitter, call the service as following:
twitterService.update("I am fine so far")

No comments:

Post a Comment