为什么我的 ajax 在查询 yelp api 时出现验证错误?

Why is my ajax having a validation error querying yelp api?

这里是第一个问题,如有不妥还请见谅

我有以下代码:

function getMapPlaces() {
  var key =
    "_961jkjpPEKGMX6YlEZm8awCLH1avefv5RUIhm6ciV_8kfRRr-gRay5GIICt9Ih-ggqoKNJdnSD7rBuIwmcbiaHSLUFWeJmOaHmzO5t4UwYvJCfX7hy38gy4IhUWX3Yx;";
  var settings = {
    async: true,
    crossDomain: true,
    url:
      "https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search",
    method: "GET",
    headers: {
      Authorization: "Bearer " + key,
      //"x-rapidapi-host": "YelpAPIserg-osipchukV1.p.rapidapi.com",
      //"x-rapidapi-key": "629a103ae7msh8d2e000534865ffp18dc6ejsna10a77d719b1",
      //"content-type": "application/x-www-form-urlencoded",
    },
    data: {
      location: "Harrisburg",
      accessToken:
        "_961jkjpPEKGMX6YlEZm8awCLH1avefv5RUIhm6ciV_8kfRRr-gRay5GIICt9Ih-ggqoKNJdnSD7rBuIwmcbiaHSLUFWeJmOaHmzO5t4UwYvJCfX7hy38gy4IhUWX3Yx",
    },
  };

  $.ajax(settings).done(function (response) {
    console.log(response);
  });
}

getMapPlaces();

但是出现以下错误:

{错误:{代码:“VALIDATION_ERROR”,…}} 错误:{代码:“VALIDATION_ERROR”,…} 代码:“VALIDATION_ERROR” 描述:“'Bearer ;' 不匹配 '^(?i)Bearer [A-Za-z0-9\-\_]{128}$'” 领域:“授权” 实例:“承载者;”

用我的 api 密钥替换 .我在这里做错了什么?

尝试删除 key 值末尾的 semicolon (;)(字符串中的最后一个字符)。

正则表达式 ([A-Za-z0-9\-\_]{128}$) 错误似乎不言自明。

您的授权header与他们提供的验证正则表达式不匹配。自己看看:

var key = "_961jkjpPEKGMX6YlEZm8awCLH1avefv5RUIhm6ciV_8kfRRr-gRay5GIICt9Ih-ggqoKNJdnSD7rBuIwmcbiaHSLUFWeJmOaHmzO5t4UwYvJCfX7hy38gy4IhUWX3Yx;";
var authorizationHeader = "Bearer " + key;
var validator = new RegExp('^Bearer [A-Za-z0-9\-\_]{128}$');
authorizationHeader.match(validator);