Node.js 如何使用express和axios从Linkedin API获取访问令牌?
我正在学习Linkedin API以使用“使用Linkedin登录”功能。 我正在使用axios获取accessToken,但出现以下错误: 错误:“无效的\u重定向\u uri”Node.js 如何使用express和axios从Linkedin API获取访问令牌?,node.js,authentication,axios,access-token,linkedin-api,Node.js,Authentication,Axios,Access Token,Linkedin Api,我正在学习Linkedin API以使用“使用Linkedin登录”功能。 我正在使用axios获取accessToken,但出现以下错误: 错误:“无效的\u重定向\u uri” data: { error: 'invalid_redirect_uri', error_description: 'Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization c
data: {
error: 'invalid_redirect_uri',
error_description: 'Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists'
}
问题是,在Postman上,重定向uri完全相同,它可以工作,我得到了访问令牌,而在express上,我得到了上面提到的错误
async function getAccessToken(authCode) {
try {
const response = await axios.post('https://www.linkedin.com/oauth/v2/accessToken', null, {
params: {
grant_type: 'authorization_code',
code: authCode,
redirect_uri: 'https%3A%2F%2Fswift-front.netlify.app',
client_id:'86v3d75uyj2qp4',
client_secret: itsASecret
},
})
console.log(response);
} catch (error) {
console.log(error)
}
}
getAccessToken(authCode);
我想我的错误在某种程度上是因为我通过了那些情人。无法找出错误的确切原因。只有在请求授权码时,才必须对重定向uri进行编码,但在请求访问令牌时,使用重定向URL而不对其进行编码