2015-05-15 80 views
1

我想用shopify api创建产品,但产品没有设置,我没有得到任何错误。 print_r($server_output);什么都不显示,所以我看不出我错在哪里。卷曲也被启用。以下是我使用的代码。
当我print_r($products);它显示阵列应该如何。难道我做错了什么?正确shopify api产品创建

$name='test product 555'; 
$group=36; 
$quantity=20; 
$price='20.95'; 

$url = 'https://my_key_and_pass/admin/products.json'; 
$type = 'POST'; 
$product = array('title' => utf8_encode($name), 
     'body_html' => utf8_encode($name), 
     'product_type'=> $group, 
     'variants' => array(
     array('price' => $price, 
     'inventory_quantity'=> $quantity, 
     'inventory_management' => 'shopify' 
     ) 
     ) 
     ); 

$ch = curl_init($url); 
$data_string = json_encode(array('product'=>$product)); 
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     'Content-Type: application/json', 
     'Content-Length: ' . strlen($data_string)) 
     ); 
$server_output = curl_exec ($ch); 
print_r($server_output); 
curl_close ($ch); 
+1

的问题是,我不清楚。也许描述你的期望,而你取而代之? – kebs

+0

您应该改用node.js。 –

+0

哈!用于业余爱好者的螺杆node.js。改用Fortran并成为一个真正的人。这些人使用猫脚本语言... pffft。 –

回答

0

问题是,主机没有启用SSL所以这段代码解决它:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
0

我不是太熟悉PHP /卷曲,但你可能会丢失后场计数:

curl_setopt($ch, CURLOPT_POST, count($data_string)); 

curl_setopt($ch, CURLOPT_POST, 1); 

,因为你只有一个产品。

你有没有在像邮递员这样的应用程序尝试?它在那里工作吗?