0

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 );


}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • when I hit url in chrome using oauth_verifier and oauth_token recieved in callback controller, I am getting access token and access token secret. so there is no problem with credentials. Below is the URL i used. https://api.twitter.com/oauth/access_token?oauth_verifier=ABC&oauth_token=AAA-CCC_DDD – padmarag pednekar May 10 '17 at 07:38

1 Answers1

0

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.