Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Javascript API检索linkedin用户的完整配置文件_Javascript_Api_Linkedin - Fatal编程技术网

如何通过Javascript API检索linkedin用户的完整配置文件

如何通过Javascript API检索linkedin用户的完整配置文件,javascript,api,linkedin,Javascript,Api,Linkedin,我正试图通过Javascript API检索linkedin用户的完整档案(尤其是工作经历和学历)。我已设法从google和stack overflow中拼凑出以下代码: <html> <head> <title>Test</title> <script type="text/javascript" src="http://platform.linkedin.com/in.js"> api_key: blahblahblah

我正试图通过Javascript API检索linkedin用户的完整档案(尤其是工作经历和学历)。我已设法从google和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>

试验
api_键:blahblahblah
onLoad:onLinkedInLoad
授权:正确
函数onLinkedInLoad(){
IN.Event.on(在“auth”中,onLinkedInAuth);
}
函数onLinkedInAuth(){
IN.API.Profile(“me”).result(displayProfiles);
//在.API.Profile(“me”)字段中([“行业”、“网络”、“出生日期”、“教育程度:(id、学校名称)”))。结果(显示配置文件);
}
函数显示配置文件(配置文件){
成员=配置文件。值[0];
document.getElementById(“profiles”).innerHTML=
“

Hello“+member.firstName+”“+member.lastName+”

”; 用于(个人资料中的教育。教育){ var id=education.id; var name=education.schoolName; console.log(名称); } }

这将在授予访问权限后,设法检索登录用户的姓名。然而,它完全无法检索任何其他内容。我正在使用linkedin的公司登录,我可以通过RESTAPI访问所有用户信息,因此这不是访问问题;我只是不知道(也找不到任何例子)如何使用Javascript API。如何指定要检索的信息以及如何在返回的JSON对象中识别该信息?

通过使用您注释掉的调用的变体,我认为这一点很有效: 检查您可以使用的,您有“网络”在那里,但它没有列出。也许它是旧版本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);
}
然后您可以像这样处理返回的数据:

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...
   });
}
功能显示配置文件(配置文件){
var成员=profiles.values[0];
//请注意,这些值是数组而不是对象
var educations=member.educations.values;
变量位置=成员位置值;
document.getElementById('profiles').innerHTML=
“

您好“+member.firstName+”+member.lastName+”

”; 教育。forEach(功能(edu){ 变量id=教育单位id; var name=edu.schoolName; console.log(id,name); }); 位置。forEach(功能(位置){ //对每个职位做一些工作。。。 }); }
给了我一个类型错误:member.educations对于它工作的位置是未定义的,但它只返回当前位置;不是所有位置。听起来你的应用程序只设置了权限。进入你的linkedin开发者,确保你的“r_fullprofile”框被选中。出于某种原因,“r_fullprofile”甚至没有列出,即使它是公司帐户。r_fullprofile也没有列在我的非公司帐户上。