简体   繁体   English

我无法通过axios获取linkedin访问令牌,保持状态为400

[英]I can't get the linkedin access token with axios, keep getting status 400

The API says that status code 400 is probably syntax error, but I wasn't able to find it. 该API指出状态代码400可能是语法错误,但我找不到它。 I already have the authentication code and app credentials, and the url is registered. 我已经有了身份验证代码和应用程​​序凭据,并且该URL已注册。

I've tried with and without qs. 我尝试过和不使用qs。

exports.getAccessToken = (req, res, next) => {
    let payload = req.body;
    let request_body = qs.stringify({
        "grant_type": "authorization_code",
        "code": payload.code,
        "redirect_uri": linkedin.redirect_uri,
        "client_id": linkedin.clientId,
        "client_secret": linkedin.clientSecret
    });
    let config = {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
    };
    axios.post("https://www.linkedin.com/oauth/v2/accessToken", request_body, config).then(
        response => {
            res.json(response.data);
        },
        error => {
            res.json(error);
        }
    );
}

You are using the wrong url to get accesstoken. 您使用了错误的URL来获取访问令牌。

  • Step 1 第1步

First you need to use following url 首先,您需要使用以下网址

curl -X GET \
  'https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=[CLIENT_ID]&redirect_uri=https://getpostman.com/oauth2/callback&state=CA&scope=r_emailaddress%20r_ads%20w_organization_social%20rw_ads%20r_basicprofile%20r_liteprofile%20r_ads_reporting%20r_organization_social%20rw_organization_admin%20w_member_social' \
  -H 'Postman-Token: 1c7d6199-f41b-43bc-b9ae-10d4bde0d968' \
  -H 'cache-control: no-cache'

Response contains code which needs to used in Step 2 响应包含在步骤2中需要使用的代码

  • Step 2 第2步

use CODE received from Step 1 使用从步骤1收到的CODE

curl -X GET \
  'https://www.linkedin.com/oauth/v2/accessToken?grant_type=authorization_code&code=[CODE]&redirect_uri=https://getpostman.com/oauth2/callback&client_id=[CLIENT_ID]&client_secret=[CLIENT_SECRET]' \
  -H 'Postman-Token: f9542a93-fc9d-4cc4-aa38-a10f6cf2eb6f' \
  -H 'cache-control: no-cache'

This will give you the access Token 这将为您提供访问令牌

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 axios 获取linkedin 的访问令牌 - Unable to get access token for linkedin using axios 如何从linkedin中的Access Token API获取AccessToken - How can i get AccessToken from API of Access Token in linkedin 如何使用 express 和 axios 从 Linkedin API 获取访问令牌? - How to get the access token from Linkedin API with express and axios? 使用 axios 获取访问令牌 - Getting access token with axios Axios 无法获取访问令牌? - Axios is not working to get access token? 我想获取我的 Graph API 令牌,但出现错误,我正在使用 HttpServices 发出 POST 请求。 我收到 400 状态码。 我正在使用 NestJS - I want to get my Graph API token but I got an error, I'm making a POST request with HttpServices. I'm getting a 400 status code. I'm using NestJS 如果节点服务器发送状态400,则获取axios响应 - Getting axios response if Node server sends status 400 通过 Oath2 从 LinkedIn 获取访问令牌后如何获取用户个人资料数据 - How to get user profile data after getting access token from LinkedIn via Oath2 当我使用 Discord OAuth2 时,我收到错误 400。我怎样才能让它正确返回 access_token? - When I use Discord OAuth2 I am getting error 400. How can I make this return the access_token correctly? 无法从亚马逊获取访问令牌 - Can't get access token from amazon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM