【发布时间】:2023-03-29 14:01:01
【问题描述】:
我有一个小型节点应用程序,它在使用 Oath2 进行身份验证(授权)后从 LinkedIn 检索访问令牌。
现在我有了令牌,我想发出后续请求以获取用户个人资料数据。问题是当我提出请求时,错误提示如下:
{"success":false,"msg":"403 - {\"serviceErrorCode\":100,\"message\":\"Not enough permissions to access: GET /me\",\"status\":403}"}
我已经检查了 LinkedIn 应用程序中的所有“状态”选项。
根据 LinkedIn API 文档,令牌需要在标头中发送。像这样:
(参考:https://developer.linkedin.com/docs/oauth2#requests)
获取profile数据的路径如下: https://api.linkedin.com/v2/me
这是我希望用户获取他们的个人资料数据的途径:
app.get("/user",async (req,res)=>{
console.log(token); /* token object is available in higher scope from previous request */
var options = {
url: "https://api.linkedin.com/v2/me",
method: 'GET',
headers: {
'Host': "api.linkedin.com",
'Connection': "Keep-Alive",
'Authorization': 'Bearer ' + token.access_token
},
json: true // Automatically stringifies the body to JSON
};
try {
var response = await makeRequest(options);
return res.json({success:true})
} catch (err) {
return res.json({ success: false, msg: err.message});; // TypeError: failed to fetch
}
});
【问题讨论】:
标签: javascript node.js oauth-2.0 linkedin-api