Square API 不会 Return 位置列表 - 无效请求错误

Square API Won't Return List of Locations - Invalid Request Error

这是我的代码:

// Build request URL
$url = 'https://connect.squareup.com/v2/locations/';

// Build and execute CURL request
$options = array(
    CURLOPT_RETURNTRANSFER => true, // return web page
    CURLOPT_HEADER => false, // don't return headers
    CURLOPT_FOLLOWLOCATION => true, // follow redirects
    CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
    CURLOPT_ENCODING => "", // handle compressed
    CURLOPT_AUTOREFERER => true, // set referrer on redirect
    CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
    CURLOPT_TIMEOUT => 120, // time-out on response
    CURLOPT_CUSTOMREQUEST => 'GET', 
    CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer ' . $accessToken,
        'Accept: application/json',
    ) 
);

$ch = curl_init($url);
curl_setopt_array($ch, $options);

$content = curl_exec($ch);

curl_close($ch);
var_dump($content);

这是我得到的结果:

string(158) "{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"API endpoint for URL path `/v2/locations/` and HTTP method `GET` is not found."}]}"

我正在为这个问题绞尽脑汁...我尝试使用 Square SDK,但从中调用也没有 return 位置列表。

我已经在 Square Developer Dashboard 上创建了一个应用程序。 $accessToken 设置为此处列出的沙盒访问令牌。

您在 url 的末尾添加了额外的 /。您应该改用:

$url = 'https://connect.squareup.com/v2/locations';

除此之外,您的代码有效!