【问题标题】:How to get the access token from Linkedin API with express and axios?如何使用 express 和 axios 从 Linkedin API 获取访问令牌?
【发布时间】:2021-05-07 20:06:19
【问题描述】:

我正在研究 Linkedin API 以使用“使用 Linkedin 登录”功能。 我正在使用 axios 获取 accessToken 但我收到此错误: 错误:'invalid_redirect_uri',

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 上,redirect_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);

我想我的错误在于我传递参数的方式。无法弄清楚究竟是什么错误。

【问题讨论】:

    标签: node.js authentication axios access-token linkedin-api


    【解决方案1】:

    redirect_uri 仅在您请求授权码时必须进行编码,但当您请求访问令牌时,您使用重定向 URL 而不对其进行编码。

    【讨论】:

      猜你喜欢
      • 2020-11-06
      • 1970-01-01
      • 2012-04-09
      • 2017-01-07
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 2017-06-02
      相关资源
      最近更新 更多