Using linkedin-j, I have the following code in one part of my application
LinkedInOAuthService service = LinkedInOAuthServiceFactory.getInstance()
.createLinkedInOAuthService(consumerKey, consumerSecret);
LinkedInRequestToken requestToken =
service.getOAuthRequestToken(linkedinCallbackURL);
String authUrl = requestToken.getAuthorizationUrl();
I redirect to the page pointed by authUrl
and get to the correct LinkedIn page where I authorize my application. Then, the code which generates the page pointed by linkedinCallbackURL
will execute this:
String verifier = request.getParameter("oauth_verifier");
LinkedInOAuthService oauthService =
LinkedInOAuthServiceFactory.getInstance()
.createLinkedInOAuthService(consumerKey, consumerSecret);
LinkedInRequestToken requestToken = oauthService.getOAuthRequestToken();
LinkedInAccessToken accessToken = oauthService
.getOAuthAccessToken(requestToken, verifier);
Unfortunately, I get this error:
com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Server returned HTTP response code: 401 for URL: https://api.linkedin.com/uas/oauth/accessToken
Caused by: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Server returned HTTP response code: 401 for URL: https://api.linkedin.com/uas/oauth/accessToken
What can be wrong?