【问题标题】:Square API Won't Return List of Locations - Invalid Request ErrorSquare API 不会返回位置列表 - 无效请求错误
【发布时间】:2018-05-17 00:00:03
【问题描述】:

这是我的代码:

// 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,但从它调用也不会返回位置列表。

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

【问题讨论】:

    标签: php api square square-connect


    【解决方案1】:

    您在网址末尾添加了一个额外的/。你应该改用:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-05
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多