Fetch LinkedIn Data Using JavaScript

Here we are fetching LinkedIn data like Username, Email and other fields using JavaScript SDK. We can also fetch any company specific data like company job updates/post, total likes, comments, and number of views along with a lot of metadata we can fetch which I have shown below.
 
Here we have 2 workarounds.
  1. Configuration of linkedIn developer api
  2. Javascript Code to fetch records 
Configuration of linkedIn developer api
  
In order to fetch records, first we need to create developer api in linkedin which will act as token/identity while fetching data from other linkedin accounts. 
 
So to create api, navigate to https://linkedin.com/developer/apps and click on 'Create Application'.

JavaScript

After navigating, fill in details like name, description and other required fields and then submit.
 
As we submit, it will create Client ID and Client Secret shown below, which we will be using in our code while communicating to fetch records from other LinkedIn account.

JavaScript

Note

We need to provide localhost Url here under Oauth 2.0. I am using my localhost, but you can probably use other production URLs under Oauth 2.0 where your app is configured. It will make your api  consider the Url as trusted which fetching records.
 
Javascript Code to fetch records
 
For getting user details like first name, last name,User image can be written as,
  1. <script type="text/javascript" src="https://platform.linkedin.com/in.js">  
  2.     api_key: XXXXXXX //Client ID  
  3.     onLoad: OnLinkedInFrameworkLoad //Method that will be called on page load  
  4.     authorize: true  
  5. </script>  
  6. <script type="text/javascript">  
  7.     function OnLinkedInFrameworkLoad() {  
  8.         IN.Event.on(IN, "auth", OnLinkedInAuth);  
  9.     }  
  10.   
  11.     function OnLinkedInAuth() {  
  12.         IN.API.Profile("me").result(ShowProfileData);  
  13.     }  
  14.   
  15.     function ShowProfileData(profiles) {  
  16.         var member = profiles.values[0];  
  17.         var id = member.id;  
  18.         var firstName = member.firstName;  
  19.         var lastName = member.lastName;  
  20.         var photo = member.pictureUrl;  
  21.         var headline = member.headline;  
  22.         //use information captured above  
  23.         var stringToBind = "<p>First Name: " + firstName + " <p/><p> Last Name: " + lastName + "<p/><p>User ID: " + id + " and Head Line Provided: " + headline + "<p/>"  
  24.         document.getElementById('profiles').innerHTML = stringToBind;  
  25.     }  
  26. </script>    
Kindly note we need to include 'https://platform.linkedin.com/in.js' as src under script type as it will act on this Javascript SDK provided by Linkedin.
 
In the same way we can also fetch records of any organization with the companyid as keyword.
  1. <head>  
  2.     <script type="text/javascript" src="https://platform.linkedin.com/in.js">  
  3.         api_key: XXXXXXX ////Client ID  
  4.         onLoad: onLinkedInLoad  
  5.         authorize: true  
  6.     </script>  
  7. </head>  
  8.   
  9. <body>  
  10.     <div id="displayUpdates"></div>  
  11.     <script type="text/javascript">  
  12.         function onLinkedInLoad() {  
  13.             IN.Event.on(IN, "auth", onLinkedInAuth);  
  14.             console.log("On auth");  
  15.         }  
  16.   
  17.         function onLinkedInAuth() {  
  18.             var cpnyID = XXXXX; //the Company ID for which we want updates  
  19.             IN.API.Raw("/companies/" + cpnyID + "/updates?event-type=status-update&start=0&count=10&format=json").result(displayCompanyUpdates);  
  20.             console.log("After auth");  
  21.         }  
  22.   
  23.         function displayCompanyUpdates(result) {  
  24.             var div = document.getElementById("displayUpdates");  
  25.             var el = "<ul>";  
  26.             var resValues = result.values;  
  27.             for (var i in resValues) {  
  28.                 var share = resValues[i].updateContent.companyStatusUpdate.share;  
  29.                 var isContent = share.content;  
  30.                 var isTitled = isContent,  
  31.                     isLinked = isContent,  
  32.                     isDescription = isContent,  
  33.                     isThumbnail = isContent,  
  34.                     isComment = isContent;  
  35.                 if (isTitled) {  
  36.                     var title = isContent.title;  
  37.                 } else {  
  38.                     var title = "News headline";  
  39.                 }  
  40.                 var comment = share.comment;  
  41.                 if (isLinked) {  
  42.                     var link = isContent.shortenedUrl;  
  43.                 } else {  
  44.                     var link = "#";  
  45.                 }  
  46.                 if (isDescription) {  
  47.                     var description = isContent.description;  
  48.                 } else {  
  49.                     var description = "No description";  
  50.                 }  
  51.                 /* 
  52.                 if (isThumbnailz) { 
  53.                 var thumbnailUrl = isContent.thumbnailUrl; 
  54.                 } else { 
  55.                 var thumbnailUrl = "http://placehold.it/60x60"; 
  56.                 } 
  57.                 */  
  58.                 if (share) {  
  59.                     var content = "<a target='_blank' href=" + link + ">" + comment + "</a><br>";  
  60.                     //el += "<li><img src='" + thumbnailUrl + "' alt=''>" + content + "</li>";  
  61.                     el += "<li><div>" + content + "</div></li>";  
  62.                 }  
  63.                 console.log(share);  
  64.             }  
  65.             el += "</ul>";  
  66.             document.getElementById("displayUpdates").innerHTML = el;  
  67.         }  
  68.     </script>  
  69. </body>  
We can get multiple metadata while fetching records for any any organization. We can get company updates as shown below.
 
JavaScript

I have provided the whole code above which has been tested at my end.
Kindly let me know if you have any issues.