4

I've pasted my code below. I'm getting an empty string back, no curl error or anything.

$service_url = "https://api.insight.ly/v2.1/Opportunities";           
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key");

$data = curl_exec($ch);
curl_close($ch);

since the documentation for the Insightly API said to leave password blank, i've also tried

 curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key:"); 

and

 curl_setopt($ch, CURLOPT_USERPWD, "-my-base64-encoded-api-key: ");

Any help would be appreciated. Thank you.

4

1 回答 1

7

下面是工作代码 - 我必须在标题中发送授权,而不是作为 CURL 中的选项。我不知道这是可能的。有洞察力的支持来了,并为我提供了额外的说明。我在下面发布答案,以防其他人遇到这个问题。

$service_url = 'https://api.insight.ly/v2.1/Opportunities';
$ch = curl_init($service_url);           
curl_setopt($ch, 
            CURLOPT_HTTPHEADER, 
            array('Content-Type: application/json', 
                  'Authorization: Basic my-base64-encoded-api-key'));
curl_setopt($ch , CURLOPT_HEADER, 0);           
curl_setopt($ch , CURLOPT_TIMEOUT, 30);           
curl_setopt($ch , CURLOPT_HTTPGET, 1);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, TRUE);            

$return = curl_exec($ch );    

curl_close($process);
于 2013-10-28T18:54:56.860 回答