簡體   English   中英

通過 Oath2 從 LinkedIn 獲取訪問令牌后如何獲取用戶個人資料數據

[英]How to get user profile data after getting access token from LinkedIn via Oath2

我有一個小型節點應用程序,它在使用 Oath2 進行身份驗證(授權)后從 LinkedIn 檢索訪問令牌。

現在我有了令牌,我想發出后續請求以獲取用戶配置文件數據。 問題是,當我提出請求時,錯誤顯示如下:

{"success":false,"msg":"403 - {\"serviceErrorCode\":100,\"message\":\"Not enough permissions to access: GET /me\",\"status\":403}"}

我已經勾選了 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
    }



});

嘗試在 Bearer 一詞后添加一個空格。 目前,它將您的令牌和單詞Bearer視為單個字符串,並且不知道從哪里拆分以獲取令牌

'Authorization': 'Bearer ' + token.access_token

暫無
暫無

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

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