简体   繁体   English

如何通过Javascript API检索linkedin用户的完整资料

[英]How to retrieve full profile of linkedin user via Javascript API

I am trying to retrieve the full profile (especially job history and educational qualifications) of a linkedin user via the Javascript API.我正在尝试通过 Javascript API 检索linkedin 用户的完整个人资料(尤其是工作经历和学历)。 I have managed to piece together the following code from google and stack overflow:我已经设法从谷歌和堆栈溢出中拼凑出以下代码:

<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
    api_key:   blahblahblah
    onLoad:    onLinkedInLoad
    authorize: true
</script>

<script type="text/javascript">
function onLinkedInLoad() {
   IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
   IN.API.Profile("me").result(displayProfiles);
   // IN.API.Profile("me").fields(["industry", "network", "date-of-birth", "educations:(id,school-name)"]).result(displayProfiles);
}
function displayProfiles(profiles) {
   member = profiles.values[0];
   document.getElementById("profiles").innerHTML =
   "<p id=\"" + member.id + "\">Hello " + member.firstName + " " + member.lastName + "</p>";

   for(education in profiles.educations) {
      var id = education.id;
      var name = education.schoolName;
      console.log(name);
   }
}
</script>
</head>
<body>
<script type="IN/Login"></script>
<div id="profiles"></div>
</body>
</html>

This manages to retrieve the logged in user's name and surname after they grant access.这设法在授予访问权限后检索登录用户的姓名和姓氏。 However it completely fails to retrieve anything else.然而,它完全无法检索其他任何东西。 I am using a company login for linkedin and I can access all the user's information via the rest api, so it's not an access issue;我正在使用公司登录名进行linkedin,我可以通过rest api访问所有用户的信息,所以这不是访问问题; I just don't know (and can't find any examples) of how to use the Javascript API.我只是不知道(也找不到任何示例)如何使用 Javascript API。 How would I specify what information to retrieve and how would I then identify that information in the returned JSON object?我将如何指定要检索的信息以及如何在返回的 JSON 对象中识别该信息?

Seems to work on my end by using a variation of the call you had commented out: Check the fields you can use, you had "network" in there but it is not listed. 似乎可以使用您注释掉的呼叫的一种变体来实现我的目的:检查您可以使用的字段 ,您那里有“网络”,但未列出。 Maybe it was part of an older version of the API? 也许它是旧版API的一部分?

function onLinkedInAuth() {
  // IN.API.Profile('me').result(displayProfiles);
  IN.API.Profile('me').fields([
    'first-name', 'last-name', // Add these to get the name
    'industry', 'date-of-birth', 'educations:(id,school-name)',
    'positions' // Add this one to get the job history
  ])
  .result(displayProfiles);
}

Then you can work with the returned data like this: 然后,您可以像这样处理返回的数据:

function displayProfiles(profiles) {
  var member = profiles.values[0];

  // Note that these values are arrays and not objects
  var educations = member.educations.values;
  var positions = member.positions.values;

  document.getElementById('profiles').innerHTML =
   '<p id="' + member.id + '">Hello ' + member.firstName + ' ' + member.lastName + '</p>';

   educations.forEach(function(edu) {
     var id = edu.id;
     var name = edu.schoolName;
     console.log(id, name);
   });

   positions.forEach(function(position) {
     // Do some work with each position...
   });
}

If you want to fetch user profile data then you can modify the linkedin profile badge using javascript and get data of user without authtoken and api如果要获取用户个人资料数据,则可以使用 javascript 修改linkedin 个人资料徽章,并在没有 authtoken 和 api 的情况下获取用户数据

LinkedIn-Profile-Data-Fetch-Without-API-Using Javascript with profile badge LinkedIn-Profile-Data-Fetch-Without-API-使用带有个人资料徽章的 Javascript

 let lkList = ["devsalmanshaikh", "ravi95"]; let linkedinid = ""; let idx = 0; let badgeElm = document.getElementById("hideBadgeElm"); let waitObserver; getData(); function getData() { linkedinid = lkList[idx]; badgeElm.innerHTML = `<div class="badge-base LI-profile-badge" data-locale="en_US" data-size="medium" data-theme="light" data-type="VERTICAL" data-vanity="${linkedinid}" data-version="v1"><a class="badge-base__link LI-simple-link" href="https://in.linkedin.com/in/${linkedinid}?trk=profile-badge">.</a></div>`; loadProfileJs(); } function loadProfileJs() { var script = document.createElement("script"); script.onload = function() { waitObserver = setInterval(domObserve, 1000); }; script.src = "https://platform.linkedin.com/badges/js/profile.js"; document.head.appendChild(script); } function domObserve() { let state = badgeElm.querySelector(".LI-profile-badge .profile-badge__header"); if (state) { clearInterval(waitObserver); console.log(state); let json = { id: linkedinid, img: "#", name: "Not available", title: "Not available", info: "Not available", }; if (badgeElm.querySelector("img.profile-badge__content-profile-image")) { json.img = badgeElm.querySelector("img.profile-badge__content-profile-image").src; } if (badgeElm.querySelector(".profile-badge__content-profile-name")) { json.name = badgeElm.querySelector(".profile-badge__content-profile-name").innerText; } if (badgeElm.querySelector(".profile-badge__content-profile-headline")) { json.title = badgeElm.querySelector(".profile-badge__content-profile-headline").innerText; } if (badgeElm.querySelector(".profile-badge__content-profile-company-school-info")) { json.info = badgeElm.querySelector(".profile-badge__content-profile-company-school-info").innerText; } showData(json); } } function showData(json) { let tbl = "<table border=1><tbody>"; for (i in json) tbl += `<tr><td class='col0'>${i}</td><td class='col1'>${json[i]}</td></tr>`; output.innerHTML += tbl + "</tbody></table>"; idx++; if (idx < lkList.length) getData(); }
 <div id="output" style="padding: 12px;"></div> <div id="hideBadgeElm" style="display: none;"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我们具有该用户的个人资料ID,则如何使用LinkedIn Javascript API获取其他用户的个人资料详细信息 - How to fetch profile details of another user using LinkedIn Javascript API, if we have profile id of that user 使用JavaScript和REST API检索LinkedIn个人资料图片 - Retrieve LinkedIn Profile Picture Using JavaScript with REST API Linkedin Javascript Profile API损坏 - Linkedin Javascript Profile API broken 使用Linkedin API检索我的个人资料信息 - Use Linkedin API to retrieve my profile info 如何使用 javascript 在 Liferay 中检索用户资料图片 - How to retrieve a user profile picture in Liferay with javascript 如何使用Linkedin API获取用户的LinkedIn个人资料网址 - How Can I Get User's LinkedIn Profile Url using Linkedin API 通过 Oath2 从 LinkedIn 获取访问令牌后如何获取用户个人资料数据 - How to get user profile data after getting access token from LinkedIn via Oath2 如何使用linkedin API获取linkedin上的个人资料的网址 - How can I get the url of a profile on linkedin using the linkedin API 我可以通过API获得Linkedin个人资料的活动状态吗? - Can I get Linkedin profile active status via API? 无法通过JavaScript加载Linkedin API - Not able to load Linkedin API via javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM