簡體   English   中英

我無法通過axios獲取linkedin訪問令牌,保持狀態為400

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

該API指出狀態代碼400可能是語法錯誤,但我找不到它。 我已經有了身份驗證代碼和應用程​​序憑據,並且該URL已注冊。

我嘗試過和不使用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);
        }
    );
}

您使用了錯誤的URL來獲取訪問令牌。

  • 第1步

首先,您需要使用以下網址

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'

響應包含在步驟2中需要使用的代碼

  • 第2步

使用從步驟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'

這將為您提供訪問令牌

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM