2016-11-13 5 views
0

私はこれを手伝ってもらえますか?私は多くの方法を試してもうまくいきません。Shopifyのテーマテンプレートcurlを使用して更新

以下は私のコードです。私はphpとcurlを使用して液体テンプレートファイルを更新しようとしていますが、それはできません。

<?php 
    error_reporting(-1); 

    $value = 'this is testing'; 

    //Code for updating file 
    //$service_url = 'https://[email protected]/admin/themes/160467719/assets.json?asset[key]=snippets/product-preview.liquid&asset[value]=7788888&theme_id=160467719'; 

    $service_url = 'https://[email protected]/admin/themes/160467719/assets.json'; 

    $curl = curl_init($service_url); 

    $curl_post_data = array(
     'asset'=> array(
       "key" => "snippets/product-akash123.liquid", 
       "value" => 'This is testing' 
      ) 
    ); 

    //echo json_encode($curl_post_data);die; 

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/x-liquid')); 
    curl_setopt($curl, CURLOPT_PUT, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data)); 
    //curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); 
    //curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($curl_post_data)); 

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 


    $curl_response = curl_exec($curl); 
    if ($curl_response === false) { 
     $info = curl_getinfo($curl); 
     var_dump(curl_error($curl)); 
     curl_close($curl); 
     die('error occured during curl exec. Additioanl info: ' . var_export($info)); 
    } 
    curl_close($curl); 
    $decoded = json_decode($curl_response); 
    echo "<pre>";print_r(curl_getinfo($curl)); 
    //echo curl_error($curl); 
    echo "<pre>"; print_r($decoded);die('loll'); 
?> 
+0

を試してください。$ service_urlの値が間違っている可能性があります。 shopify.comを2回繰り返したことがあります。 –

答えて

0

あなたはapplication/jsonContent-Typeヘッダを設定することをお勧めします。上記のコードで

<?php 
$ch = curl_init('https://key:[email protected]/admin/themes/160467719/assets.json'); 
$asset = array('asset'=> array(
    'key' => 'snippets/yournewsnippet.liquid', 
    'value' => '{% comment %} here is your new snippet {% endcomment %}' 
)); 
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($asset)); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
$response = curl_exec($ch); 
+0

いいえ、その機能していません – user2736058

関連する問題