在尝试为产品提取图片时,我的回复中一直是NULL。提出产品清单请求工作正常。我使用的是Bigcommerce API的第2版。我错过了什么? 我的代码如下:
$product_id = 82;
$organizationAccount = array(
"username" => "stores/xxxx",
"user_token" => "xxxxx"
);
$resource = 'http://api.bigcommerce.com/stores/xxxx/api/v2/products/'.$product_id.'/images.json';
$response = sendRequest($resource, 'GET', 'user_token'); //This gives null
发送请求功能
function sendRequest($url, $method, $userToken, $postFields = null, $queryData = null){
$curlHandle = curl_init();
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
if( $method == "PUT" ){
curl_setopt($curlHandle, CURLOPT_HEADER, true);
}
curl_setopt($curlHandle, CURLOPT_CUSTOMREQUEST, $method);
$httpHeader = array('Content-Type: application/json');
$url = (strpos($url, "http") !== false ) ? str_replace("http", "https", $url) : "https://" . $url;
if ($method == "POST" || $method == "PUT" || $method == "DELETE") {
curl_setopt($curlHandle, CURLOPT_URL, $url);
curl_setopt($curlHandle, CURLOPT_POST, true);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $postFields);
} elseif ($method == "GET") {
$url = (is_null($queryData)) ? $url : $url . "?" . http_build_query($queryData);
curl_setopt($curlHandle, CURLOPT_URL, $url);
}
if (!is_null($userToken)) {
$httpHeader[] = 'X-Auth-Client: ' . BC_CLIENT_ID; //Client id
$httpHeader[] = 'X-Auth-Token: ' . $userToken;
//curl_setopt($curlHandle);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $httpHeader);
}
$response = curl_exec($curlHandle);
return json_decode($response, true);
}
答案 0 :(得分:2)
错误来自端点url它应该是 $ resource ='http://api.bigcommerce.com/stores/xxxx/v2/products/'。$ product_id。'/ images.json'; 谢谢