2013-07-25 36 views
0

當我輸入到我的瀏覽器:「https://myemail:[email protected]/v3/account嘗試發送GET請求與捲曲hellosign API

我得到

{"account":{"account_id":"**************","email_address":"myemail","callback_url":null,"role_code":null}} 

這似乎是一個有效的響應。

我想在PHP中使用libcurl php庫實現這個。我有以下內容,但是當我在$ response變量上運行var_dump時會得到FALSE。任何有關libcurl設置的想法?我已經嘗試urlencoding整個字符串有和沒有base_64編碼的認證子字符串myemail:mypassword。在此先感謝:

$final_string= 'https://myemail:[email protected]/v3/account';  

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_USERAGENT, 'HelloSign-PHP'); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); 
curl_setopt($curl, CURLOPT_URL, $final_string); 
curl_setopt($curl, CURLOPT_HEADER, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::$time_out); 

$response = curl_exec($curl); 

    // Get the status code 
    $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 

    if(curl_exec($curl) === false) 
     { 
      echo 'Curl error: ' . curl_error($curl); 
     } 
     else 
     { 
      echo 'Operation completed without any errors'; 
     } 

curl_close($curl); 


output is : 

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failedProblem connecting to HelloSign. 
+1

當你說你沒有迴應時,你是什麼意思? 'curl_exec()'返回'false'? 'curl_error()'得到什麼?它應該給你一個錯誤指示。 –

+0

對不起,我回去檢查,實際上是一個布爾 - 虛假正在生產 – user61629

+0

由於用戶名和密碼是內聯的,你可以實際使用一個套接字函數。 ''echo'file_get_contents('https:// myemail:[email protected]/v3/account');' – Nadh

回答

0

嘗試以下操作:

<?php 

$api_key = 'YOUR_API_KEY'; 
$url = 'https://api.hellosign.com/v3/account'; 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":"); // Normally you'd put a password after the colon, but you don't need it if you're using an API key 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$response = curl_exec($ch); 
$response_json = json_decode($response, true); 

print_r($response_json); 

curl_close($ch); 

?> 

注意:您不需要使用您的API密鑰(您可以使用您的用戶名和密碼,如上面註釋),但它的推薦的。你可以在這裏找回你的API密鑰:https://www.hellosign.com/home/myAccount#api