Search code examples
javalinkedin-apiscribe

Unable to get skills from Linkedin API using Scribe


I'm trying to get skills information from LinkedIn using Scribe library.

Everything works. But it can not print out the skills in either XML or JSON format.

I checked the URL: https://api.linkedin.com/v1/people/~:(id,skills) in apigee. It works fine. So I'm wondering what's wrong in code.

Here is the code:

public class LinkedInExample {
   private static final String PROTECTED_RESOURCE_URL = "https://api.linkedin.com/v1/people/~:(id,skills)";

   public static void main(String[] args) {
      OAuthService service = new ServiceBuilder()
                             .provider(LinkedInApi.class)
                             .apiKey("KEY")
                             .apiSecret("SECRET")
                             .build();
      Scanner in = new Scanner(System.in);

      // Obtain the Request Token
      Token requestToken = service.getRequestToken();

      System.out.println(service.getAuthorizationUrl(requestToken));
      System.out.println("And paste the verifier here");
      System.out.print(">>");
      Verifier verifier = new Verifier(in.nextLine());

      // Trade the Request Token and Verfier for the Access Token
      System.out.println("Trading the Request Token for an Access Token");
      Token accessToken = service.getAccessToken(requestToken, verifier);
      System.out.println("Got the Access Token!");

      // Now let's go and ask for a protected resource!
      OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
      service.signRequest(accessToken, request);
      Response response = request.send();
      System.out.println(response.getBody());

   }
}

The output of this code is like:

{"id": "UU4glj53pm"}

The skills' information is missing.


Solution

  • I just find that my application has to gain r_fullprofile member permission to be able to get skills information for LinkedIn API. So there is nothing wrong in the code.