我正在尝试在BigCommerce中进行简单的API调用。我从这些链接中获得了一些信息:
我已经尝试了orders.json和orders / count,但是没有得到任何回应。我一定想念一些简单的东西。我是否必须以某种方式回应回应?
这是我的代码。
<?php
curl --request GET \
-u "username:key" \
https://store.com/api/v2/orders/count;
?>
我收到了BigCommerce的回复,这没有帮助。
我借助“如何在php curl中使用基本授权”,“使用json_decode从JSON到PHP ”和“ JSON ”的帮助下解决了这一问题。
我在运行PHP 5.6.22和curl 7.36.0的GoDaddy托管服务器上以.php文件的形式运行了此代码。
<?php
$username = "Username";
$password = "API Token";
$URL = "https://store.com/api/v2/orders/count.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //Timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Get status code
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response);
echo "Count = " . $result->count; //Total orders
echo "<br />" . $result->statuses[8]->name . " = " . $result->statuses[8]->count; //Shipped orders
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句