[英]How to get user profile data after getting access token from LinkedIn via Oath2
我有一个小型节点应用程序,它在使用 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 )
获取个人资料数据的路径如下: 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
}
});
尝试在 Bearer 一词后添加一个空格。 目前,它将您的令牌和单词Bearer
视为单个字符串,并且不知道从哪里拆分以获取令牌
'Authorization': 'Bearer ' + token.access_token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.