Announcement Announcement Module
No announcement yet.
Need to access a Company Profile from LinkedIn Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need to access a Company Profile from LinkedIn

    Hi Guys,
    I am new to Spring Social. I have a requirement wherein i need to follow below sequence of steps in order:

    1. Show a text field to user where he enters his company's linked in url
    2. Once the company profile url is entered, need to show him the linked in login page for the first time. Once he enters the valid details -> save the access tokens -> Fetch some attributes from his company profile and populate it in my page.

    My Questions:
    1. As far as i know company profile is public on Linked in and so i am wondering how to make the linked in show the login page when trying to access a Company Profile page from my Application?. Is there some kind of private company profile page which would prompt login page when tried to access without an access token?
    2. How can i validate whether the company profile url is valid and does belong to the current user from my Application (I would have the email id of the current user)

    My application is in JSF and so would like to avoid the spring mvc flow of using ConnectController..

  • #2
    Let me restate the problem to see if I got it right: You're wanting to fetch data from a company profile, but you want to force the user to sign in first to get an access token, even though you don't need an access token to fetch the company profile. Oh and you want to be sure that the company found is in fact the company "belonging" (I'm guessing this means their current employer) to the current user. Sound right?

    First, you don't need a reason to fetch an access token. You can always do the OAuth connection flow at any time, forcing the user to sign into LinkedIn, after which you will be given an access token. That's what ConnectController will do for you...but since you're using JSF, you'll need to recreate that flow for yourself. (Admittedly, I'm not a JSF expert, so while I can help you with the concepts and steps in the connection flow, I can't help you with the JSF implementation.)

    So, it sounds like step #1 in your flow is easy enough to do and step #2 will require you to implement the OAuth flow in JSF, but otherwise, there's nothing special. The unnumbered step #3, verifying that the company matches the user's company will require that access token, though. What you'll need to do is fetch the user's positions (including their company ID) and match that up with the company ID of the URL that was given in step #1.

    Unless I'm overlooking something, there's not a method in the LinkedIn API binding that will help you do step #3 (although there should be...more on that in a moment). Until such a method exists, you can always call the API directly using the RestOperations given from LinkedIn.getRestOperations() to fetch the user's profile (the RestOperations returned from LinkedIn.getRestOperations() is already outfitted to know to use the access token given when LinkedInTemplate was constructed). Here's how I fetched a few details for the current user, specifically a list of positions (company ID and name) that they've held:

    RestTemplate rest = li.getRestTemplate();
    String response = rest.getForObject(",title,company:(id,name)))", String.class);
    Here's I've fetched it into a String, but you'll probably prefer fetching it into something more suitable. For every entry where is-current is "true", you can get the company ID and use CompanyOperations.getCompany() to fetch the company data.

    All that said, your flow seems unusual to me. Why ask them about their company and then metch it up to verify that it belongs to them? Why not simply do the OAuth flow, fetch the user's positions/companies (as shown above) and then figure out which one is the current position and fetch company data from that? If the user has multiple current positions (it's possible) then you could prompt them to select the one they want to use. To me it seems burdensome on the user to paste in a company's LinkedIn URL and then later verify it when you can simply ask LinkedIn what the user's company's are.

    As for that missing API binding method that would give you the job history data, I've created to address that.


    • #3
      Isn't that supported through profileOperations().getUserProfileFull().getPositi ons()?


      • #4
        You're right...I had been looking in LinkedInProfile for that...turns out it is available in LinkedInProfileFull. Good catch!