这是我的代码:
// 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设置为其中列出的沙箱访问令牌。
答案 0 :(得分:0)
您在网址末尾添加了额外的/
。你应该使用:
$url = 'https://connect.squareup.com/v2/locations';
除了您的代码有效!