2013-07-23 49 views
1

我試圖蜷縮成bigcommerce webhooks ...雖然我得到一個我無法弄清的錯誤。CURL錯誤 - Bigcommerce Webhooks

任何想法?

JSON::ParserError at /token 

https://developer.bigcommerce.com/docs/api/webhooks/event_triggers https://developer.bigcommerce.com/docs/api/webhooks/quickstart

<?php 

    //set POST variables 
    $url = 'https://hooks-beta.bigcommerce.com/token'; 
    $fields = array(
    "client_id"=>"client_id_goes_here", 
    "client_secret"=>"client_secret_goes_here", 
    "user"=>"demo", 
    "token"=>"token_goes_here", 
    "store_domain"=>"https://domain_goes_here.mybigcommerce.com/api/v2" 
     ); 

    //open connection 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 30); 

    $result = curl_exec($ch); 
     if ($result === false) { 
      echo '<textarea>'.curl_error($ch).'</textarea>'; 
     } else { 
      echo "<textarea>".$result."</textarea>"; 
     } 
     curl_close($ch); 
    ?> 
+1

返回的json是什麼樣的? –

+1

這不是json,來自'https:// hooks-beta.bigcommerce.com/token'的json看起來像'{「error」:「沒有這樣的鉤子存在!」}' –

+0

那麼解析器錯誤在哪裏/令牌發生? 正確的,它理論上應該返回類似的東西... { 「的access_token」: 「[webHooksAccessToken]」, 「製片人」: 「存儲/ [myStoreKey]」} 請參照:http://計算器。 COM /問題/ 17352146 /的Bigcommerce-網絡掛接偵聽器在護欄 – Greg

回答

1

我能夠json_encoding我的陣列來解決我的問題。

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));