Wil*_*iam 5 javascript node.js oauth-2.0 linkedin-api
我有一个小型节点应用程序,它在使用 Oath2 进行身份验证(授权)后从 LinkedIn 检索访问令牌。
现在我有了令牌,我想发出后续请求以获取用户配置文件数据。问题是,当我提出请求时,错误显示如下:
{"success":false,"msg":"403 - {\"serviceErrorCode\":100,\"message\":\"Not enough permissions to access: GET /me\",\"status\":403}"}
Run Code Online (Sandbox Code Playgroud)
我已经勾选了 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
}
});
Run Code Online (Sandbox Code Playgroud)
小智 1
尝试在“Bearer”一词后添加一个空格。目前,它将您的令牌和单词Bearer
视为单个字符串,并且不知道在哪里拆分以获取令牌
'Authorization': 'Bearer ' + token.access_token
归档时间: |
|
查看次数: |
2274 次 |
最近记录: |