{EASY} Rapid API 返回值 Dict 错误

{EASY} Rapid API returning value Dict error

我正在使用 rapid API 来获取 LinkedIn 数据。这个特殊的 API,使用一个简单的 HTTPS GET 请求和 returns json。我写的是 Google App Script (Javascript) 和 return 在 运行 测试时出现此错误。

function callLinkedInAPI () {
  // https://rapidapi.com/iscraper/api/linkedin-profiles-and-company-data/ API website
  // https://iscraper.io/docs APi Docs

    var payload = {
    "profile_id": "williamhgates",
    "profile_type": "personal",
    "contact_info": false
    }

  var headers = {
    "contentType": "application/json",
        "x-rapidapi-host": "linkedin-profiles-and-company-data.p.rapidapi.com",
        "x-rapidapi-key": "76db3a1901mshd1518c9ce779bdep1c5920jsn3e0ec4853b66"
      }

  var url = `https://linkedin-profiles-and-company-data.p.rapidapi.com/api/v1/profile-details`

  var requestOptions = {
    'method': "POST",
    'headers': headers,
    'payload': payload,
    'muteHttpExceptions': true,
    'redirect': 'follow'
    };

  var response = UrlFetchApp.fetch(url, requestOptions);
  var json = response.getContentText();
  var data = JSON.parse(json);
  
  console.log(data)

  }

我在调用 api

时收到此错误

[ { msg: 'value is not a valid dict',
       loc: [Object],
       type: 'type_error.dict' } ]

在 headers 中使用 Content-Type 而不是 contentType 并将有效负载作为字符串传递。

Content-Type:

var headers = {
  "Content-Type": "application/json",
  "x-rapidapi-host": "linkedin-profiles-and-company-data.p.rapidapi.com",
  "x-rapidapi-key": "76db3a1901mshd1518c9ce779bdep1c5920jsn3e0ec4853b66"
}

var url = `https://linkedin-profiles-and-company-data.p.rapidapi.com/api/v1/profile-details`

var requestOptions = {
  'method': "POST",
  'headers': headers,
  'payload': JSON.stringify(payload),
  'muteHttpExceptions': true,
  'redirect': 'follow'
};

或按 requestOptions 下的原样移动它(您仍然需要将有效负载作为字符串传递)

内容类型:

var headers = {
  "x-rapidapi-host": "linkedin-profiles-and-company-data.p.rapidapi.com",
  "x-rapidapi-key": "76db3a1901mshd1518c9ce779bdep1c5920jsn3e0ec4853b66"
}

var url = `https://linkedin-profiles-and-company-data.p.rapidapi.com/api/v1/profile-details`

var requestOptions = {
  'contentType':"application/json",
  'method': "POST",
  'headers': headers,
  'payload': JSON.stringify(payload),
  'muteHttpExceptions': true,
  'redirect': 'follow'
};

输出:

参考文献: