Announcement Announcement Module
Collapse
No announcement yet.
LinkedInAdapter and fetchUserProfile Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LinkedInAdapter and fetchUserProfile

    Hi Everyone,

    I have been working to integrate Spring Social into my application and I have been using the code examples from this article:

    http://harmonicdevelopment.tumblr.co...mvc-and-spring

    I have Facebook working and am moving on to LinkedIn integration.

    The challenge I have is that fetchUserProfile, below is only populating firstName, lastName and name in UserProfile.

    public UserProfile fetchUserProfile(LinkedIn linkedin) {
    LinkedInProfile profile = linkedin.profileOperations().getUserProfile();
    return new UserProfileBuilder().setName(profile.getFirstName( ) + " " + profile.getLastName()).build();
    }

    My code requires username to be populated (and ideally email, however I now understand that email is not available via the LinkedIn API - yuck - I will need to ask the user for it. I do, however, need username but it is null.

    Why isn't fetchUserProfile returning a unique id (for example id from the LinkedInProfile) in username? I really need a unique identifier to work with.

    Ultimately, I am trying to get this line below to work right in the SignupController from the sample code I linked to above.

    UserProfile userProfile = connection.fetchUserProfile();

    Thanks!

  • #2
    LinkedInProfile contains more than just firstName, lastName, and name. It contains several useful fields, including:

    - industry
    - headline
    - profilePictureUrl
    - publicProfileUrl
    - summary
    - id

    The 'id' property is a unique identifier for that user. Is this not what you need? Or were you looking for the user's login name?

    If you're looking for the user's login name, then that's their email address. You can't get that from LinkedInProfile, but you *can* get it. You'll need to (1) make sure you authorize with "r_emailaddress" in the scope and (2) call linkedIn.profileOperations().getProfileFullById(). The LinkedInProfileFull object will have the email address in it.

    Comment


    • #3
      Thank you so much for this response. It was very helpful and pointed me in the right direction.

      I ended up making a call to restOperations().getForObject() with the parameters I needed as a work around.

      I found that getProfileFullById() did not return an email address, but I could get it with a getForObject call. I'm using spring-social-linkedin 1.0.0.RC1

      String result = ((LinkedIn)connection.getApi()).restOperations().g etForObject("https://api.linkedin.com/v1/people/{id}email-address)", String.class, userProfile.getId());

      JSONObject j;
      String s = null;
      try {
      j = new JSONObject(result);

      s = j.getString("emailAddress");

      } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }

      Comment


      • #4
        You should be able to get the email address if you're using the latest 1.0.0.BUILD-SNAPSHOT build. Be aware, however, that using this build will shift you from using LinkedIn's API via OAuth 1.0a authorization to using it via their OAuth 2 authorization.

        Comment

        Working...
        X