[英]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.