Question

How does getting the AccessToken work with Twitter4J?

When I send the user to the Authorization URL and the callback URL comes back with values oauth_token & oauth_verifier how do I then use these values to create an Accesstoken? I've tried new AccessToken(token,verifier) and getOAuthAccessToken(token,verifier) but it always seems to throw back errors.

How do I correctly use there two values to create the AccessToken?

Was it helpful?

Solution

RequestToken reqToken = (RequestToken) session.getAttribute(REQUEST_TOKEN);
session.removeAttribute(REQUEST_TOKEN);

if (!reqToken.getToken().equals(oauthToken)) {
        throw new TwitterException("Wrong oauth_token");
}
AccessToken token = twitter.getOAuthAccessToken(reqToken);

You need to store the RequestToken object in the session before redirecting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top