twitter4j invalid or expired topic error

oauth
twitter4j

#1

We are developing a system that requires being able to update the status of a user. We keep getting the 401 error with code 89 invalid or expired token. We are using Grails.
This is the code to obtain the token and secret from the user. The authorization window does display and we are available to get the tokens sent by Twitter to the callback address:

import grails.converters.JSON;
import twitter4j.auth.RequestToken;
import twitter4j.TwitterFactory;
import twitter4j.Twitter;
import twitter4j.User;
import twitter4j.conf.ConfigurationBuilder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
class Twitter4jSimpleController {

    def index() { 
		Twitter twitter = new TwitterFactory().getInstance();
		twitter.setOAuthConsumer("Consumer key from our application on Twitter site", "Consumer secret from our from our application on Twitter site");
		RequestToken requestToken = twitter.getOAuthRequestToken("http://127.0.0.1:8080/TwitterPoc/success");//callback address
		println "key:" + twitter.getConfiguration().getOAuthConsumerKey();
		println "secret: " + twitter.getConfiguration().getOAuthConsumerSecret();
		String authorizationURL = requestToken.getAuthorizationURL();
		println authorizationURL
		redirect (url:authorizationURL);//display the authorization window
	}
	
	def getProfileImageUrl() {
		ConfigurationBuilder cb = new ConfigurationBuilder();
		println "params.token " + params.token;//extracted from Twitter reply to user authorization
		println "params.tokenSecret " + params.tokenSecret;//extracted from Twitter reply to user authorization
		cb.setDebugEnabled(true).setOAuthConsumerKey("Consumer key from our application on Twitter site")
		.setOAuthConsumerSecret("Consumer secret from our from our application on Twitter site")
		.setOAuthAccessToken(params.token)
		.setOAuthAccessTokenSecret(params.tokenSecret);		
		TwitterFactory factory = new TwitterFactory(cb.build());
		Twitter twitter = factory.getInstance();
		println "twitter.updateStatus=" + twitter.updateStatus("Test");
		println "twitter.getScreenName()=" + twitter.getScreenName();
		User user = twitter.showUser(twitter.getScreenName());
		println "user.profileImageURL= " + user.profileImageURL;
		println "user.screenName= " + user.screenName;
	}
}

This is the error we get

Message: 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Invalid or expired token.
code - 89

We have tested the “getProfileImageUrl” by using the token and secret from the application settings page in Twitter. It all went perfectly fine. We were able to create a Tweet in the app account.

So the problem is with the token and secret the user is generating but we cannot find what we are doing wrong.
Help will be highly appreciated.