Bigcommerce Api在php中使用curl

时间:2014-01-22 12:15:59

标签: php curl bigcommerce

我在bigcommerce上有演示商店, 商店网址:https://store-bwvr466.mybigcommerce.com/api/v2

我想使用CURL获取记录,但curl没有正常工作。 这是我的代码......

$ch = curl_init();

$urlStringData = 'http://getcomposer.org/installer ';
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10);

curl_setopt($ch, CURLOPT_URL, $urlStringData ); 


if(curl_errno($ch))
   echo 'Curl error: '.curl_error($ch);

$result = curl_exec($ch);
curl_close ($ch);  
echo '<pre>';

print_r($result);

1 个答案:

答案 0 :(得分:4)

获取订单的简单cURL代码段

$api_url = 'https://YOUR-API-PATH.mybigcommerce.com/api/v2/orders.json';

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') );
curl_setopt( $ch, CURLOPT_VERBOSE, 0 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, "YOUR-USERNAME:YOUR-API-TOKEN" );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

$response = curl_exec( $ch );

$result = json_decode($response);
print_r($result);

希望这有帮助