使用 passport-linkedin-oauth2 获取个人资料信息

getting profile information using passport-linkedin-oauth2

我正在使用 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;

我得到的是姓名,但不是电子邮件和位置。其他两个怎么获得。还有性别。

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

newUser.linkedin.name = jsonYouGave.formattedName;
newUser.linkedin.email = jsonYouGave.emailAddress;
newUser.linkedin.location = jsonYouGave.location.name;

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