【问题标题】:trying to get a list of product images using php bigcommerce library尝试使用 php bigcommerce 库获取产品图像列表
【发布时间】:2017-04-17 09:08:46
【问题描述】:

在尝试为产品提取图片时,我的回复中不断收到 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);
    }

【问题讨论】:

标签: bigcommerce


【解决方案1】:

错误来自它应该是的端点 url $resource = 'http://api.bigcommerce.com/stores/xxxx/v2/products/'.$product_id.'/images.json'; 谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多