2017-04-17 5 views
1

製品の画像を取得しようとしているときに、私の応答にNULLが続きます。製品のリストを要求するとうまくいきます。私はBigcommerce APIのバージョン2を使用しています。私は何が欠けていますか? 私のコードは以下の通りです:。。php bigcommerceライブラリを使用して製品イメージのリストを取得しようとしています

$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); 
    } 
+1

あなたは私は私のエンドポイントを見つけたカールを使用して感謝を行わないカールhttp://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php – Samir

+1

によってスローされたエラーを確認することができます終了、エンドポイントのURLにapi /を取り出し、それが動作します。再度、感謝します – adjoke

答えて

関連する問題