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/posts, total likes, comments, and a number of views along with a lot of metadata we can fetch which I have shown below.
Here we have 2 workarounds.
- Configuration of LinkedIn developer API
- 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'.
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.
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,
- <script type="text/javascript" src="https://platform.linkedin.com/in.js">
- api_key: XXXXXXX
- onLoad: OnLinkedInFrameworkLoad
- authorize: true
- </script>
- <script type="text/javascript">
- function OnLinkedInFrameworkLoad() {
- IN.Event.on(IN, "auth", OnLinkedInAuth);
- }
-
- function OnLinkedInAuth() {
- IN.API.Profile("me").result(ShowProfileData);
- }
-
- function ShowProfileData(profiles) {
- var member = profiles.values[0];
- var id = member.id;
- var firstName = member.firstName;
- var lastName = member.lastName;
- var photo = member.pictureUrl;
- var headline = member.headline;
-
- var stringToBind = "<p>First Name: " + firstName + " <p/><p> Last Name: " + lastName + "<p/><p>User ID: " + id + " and Head Line Provided: " + headline + "<p/>"
- document.getElementById('profiles').innerHTML = stringToBind;
- }
- </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.
- <head>
- <script type="text/javascript" src="https://platform.linkedin.com/in.js">
- api_key: XXXXXXX
- onLoad: onLinkedInLoad
- authorize: true
- </script>
- </head>
-
- <body>
- <div id="displayUpdates"></div>
- <script type="text/javascript">
- function onLinkedInLoad() {
- IN.Event.on(IN, "auth", onLinkedInAuth);
- console.log("On auth");
- }
-
- function onLinkedInAuth() {
- var cpnyID = XXXXX;
- IN.API.Raw("/companies/" + cpnyID + "/updates?event-type=status-update&start=0&count=10&format=json").result(displayCompanyUpdates);
- console.log("After auth");
- }
-
- function displayCompanyUpdates(result) {
- var div = document.getElementById("displayUpdates");
- var el = "<ul>";
- var resValues = result.values;
- for (var i in resValues) {
- var share = resValues[i].updateContent.companyStatusUpdate.share;
- var isContent = share.content;
- var isTitled = isContent,
- isLinked = isContent,
- isDescription = isContent,
- isThumbnail = isContent,
- isComment = isContent;
- if (isTitled) {
- var title = isContent.title;
- } else {
- var title = "News headline";
- }
- var comment = share.comment;
- if (isLinked) {
- var link = isContent.shortenedUrl;
- } else {
- var link = "#";
- }
- if (isDescription) {
- var description = isContent.description;
- } else {
- var description = "No description";
- }
-
-
-
-
-
-
-
- if (share) {
- var content = "<a target='_blank' href=" + link + ">" + comment + "</a><br>";
-
- el += "<li><div>" + content + "</div></li>";
- }
- console.log(share);
- }
- el += "</ul>";
- document.getElementById("displayUpdates").innerHTML = el;
- }
- </script>
- </body>
We can get multiple metadata while fetching records for any any organization. We can get company updates as shown below.
I have provided the whole code above which has been tested at my end.
Kindly let me know if you have any issues.