使用通行证-linkedin-oauth2获取个人资料信息

时间:2018-06-25 11:02:55

标签: node.js api linkedin

我正在使用Passport-linkedin-oauth从node.js连接到linkedin。我正在获取以下格式的结果:

  { provider: 'linkedin',
  id: 'd8UCzVLeQ4',
  displayName: 'Sunanda Saha',
  name: { familyName: 'Saha', givenName: 'Sunanda' },
  emails: [ { value: 'sunanda.saha90@gmail.com' } ],
  photos:
   [ { value: 'https://media.licdn.com/dms/image/C4D03AQFrIK2nFzHrCA/profile-displayphoto-shrink_100_100/0?e=1535587200&v=beta&t=uSLIk3r-gZ8yxdKK_X3g8M1a4usPXmkLbQbyhvhwu0w' } ],
  _raw: '{\n  "apiStandardProfileRequest": {\n    "headers": {\n      "_total": 1,\n      "values": [{\n        "name": "x-li-auth-token",\n        "value": "name:Hhbi"\n      }]\n    },\n    "url": "https://api.linkedin.com/v1/people/d8UCzVLeQ4"\n  },\n  "distance": 0,\n  "emailAddress": "sunanda.saha90@gmail.com",\n  "firstName": "Sunanda",\n  "formattedName": "Sunanda Saha",\n  "headline": "Student at National Institute of Technology Durgapur",\n  "id": "d8UCzVLeQ4",\n  "industry": "Computer Hardware",\n  "lastName": "Saha",\n  "location": {\n    "country": {"code": "in"},\n    "name": "Durgapur Area, India"\n  },\n  "numConnections": 43,\n  "numConnectionsCapped": false,\n  "pictureUrl": "https://media.licdn.com/dms/image/C4D03AQFrIK2nFzHrCA/profile-displayphoto-shrink_100_100/0?e=1535587200&v=beta&t=uSLIk3r-gZ8yxdKK_X3g8M1a4usPXmkLbQbyhvhwu0w",\n  "pictureUrls": {\n    "_total": 1,\n    "values": ["https://media.licdn.com/dms/image/C4D00AQHRGUNS3tX9nA/profile-originalphoto-shrink_900_1200/0?e=1530086400&v=beta&t=OpBcFgQZf3T6itjXiRUruXYwBmJ0E-Lth3Vk-HwSMT8"]\n  },\n  "positions": {"_total": 0},\n  "publicProfileUrl": "https://www.linkedin.com/in/sunanda-saha-b02098144",\n  "relationToViewer": {"distance": 0},\n  "siteStandardProfileRequest": {"url": "https://www.linkedin.com/profile/view?id=AAoAACLlVTIBohmGBTmRaxEcHqMt7a-RpvQakIE&authType=name&authToken=Hhbi&trk=api*a5259465*s5577785*"}\n}',
  _json:
   { apiStandardProfileRequest:
      { headers: [Object],
        url: 'https://api.linkedin.com/v1/people/d8UCzVLeQ4' },
     distance: 0,
     emailAddress: 'sunanda.saha90@gmail.com',
     firstName: 'Sunanda',
     formattedName: 'Sunanda Saha',
     headline: 'Student at National Institute of Technology Durgapur',
     id: 'd8UCzVLeQ4',
     industry: 'Computer Hardware',
     lastName: 'Saha',
     location: { country: [Object], name: 'Durgapur Area, India' },
     numConnections: 43,
     numConnectionsCapped: false,
     pictureUrl: 'https://media.licdn.com/dms/image/C4D03AQFrIK2nFzHrCA/profile-displayphoto-shrink_100_100/0?e=1535587200&v=beta&t=uSLIk3r-gZ8yxdKK_X3g8M1a4usPXmkLbQbyhvhwu0w',
     pictureUrls: { _total: 1, values: [Array] },
     positions: { _total: 0 },
     publicProfileUrl: 'https://www.linkedin.com/in/sunanda-saha-b02098144',
     relationToViewer: { distance: 0 },
     siteStandardProfileRequest:
      { url: 'https://www.linkedin.com/profile/view?id=AAoAACLlVTIBohmGBTmRaxEcHqMt7a-RpvQakIE&authType=name&authToken=Hhbi&trk=api*a5259465*s5577785*' } } }

要获取我正在使用的信息

newUser.linkedin.name = profile.displayName;
newUser.linkedin.email = profile.emailAddress;
newUser.linkedin.location = profile.location;

我得到的是姓名,但没有电子邮件和位置。如何获得另外两个。还有性别。

1 个答案:

答案 0 :(得分:0)

根据您提供的json,应该在以下格式中为您提供所需的信息。

int calculate(lua_State* L);

jsonYouGave是您在答案中更新的json。