I am trying to get access token and access token secret of a user after authorization. getting this exception when i click on Authorize App. below is the code in callback controller. I have configured callback url in the consumer application setting.
@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public void connect(@RequestParam("oauth_token") String oauthToken,@RequestParam("oauth_verifier") String oauthVerifier){
TwitterConnectionFactory connectionFactory = new TwitterConnectionFactory( "XXX", "XXX" );
OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
OAuthToken requestToken = oauthOperations.fetchRequestToken("htt*://localhost:8080/svc/v1/authorize",null);
///String authorizeUrl = oauthOperations.buildAuthorizeUrl(requestToken.getValue(),null);
OAuthToken accessToken = oauthOperations.exchangeForAccessToken(new AuthorizedRequestToken(requestToken, oauthVerifier), null);
String consumerKey = "..."; // The application's consumer key
String consumerSecret = "..."; // The application's consumer secret
String token = accessToken.getValue();
String tokenSecret = accessToken.getSecret();
System.out.println("token: "+token);
Twitter twitter = new TwitterTemplate( consumerKey, consumerSecret, token, tokenSecret );
}
I could fetch the accesstoken and accesstokensecret after authorization. The problem was with creating requestToken. replaced the object creation of OAuthToken as follows.
OAuthToken requestToken = new OAuthToken(oauthToken, oauthVerifier);
and it worked.