我正在尝试使用以下代码从Google+中提取份额:
function get_gplus_shares($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl_results = curl_exec ($curl);
curl_close ($curl);
$json = json_decode($curl_results, true);
return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}
它在我的本地测试环境中工作正常,但不能在我的实时环境中工作。我使用php_curl
和sudo apt-get install curl
安装了sudo apt-get install php5-curl
,这工作正常。还cacert.pem
添加了sudo wget http://curl.haxx.se/ca/cacert.pem -O /usr/lib/ssl/certs/cacert.pem
。但似乎没有用。我真的不知道从哪里开始。
错误消息 - 来自apache错误日志。
RSA server certificate is a CA certificate (BasicConstraints: CA == TRUE !?)
- 但在添加cacert.pem
后,此错误似乎已修复。
PHP Notice: Undefined index: result
- PHP错误,因为该函数的结果为空。
[ssl:error] [pid 20743] AH02032: Hostname **IP-ADDRESS** provided via SNI and hostname **mydomain.com** provided via HTTP are different
- 刚看到此错误,不确定是否相关。
答案 0 :(得分:1)
您可以通过添加以下两个选项进行检查
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($ch, CURLOPT_CAINFO, "pathto/cacert.pem");
答案 1 :(得分:1)
检查以下是否有效:
<?PHP
// connect via SSL, but don't check cert
$handle=curl_init('https://www.google.com');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
$content = curl_exec($handle);
echo $c
?>