php_curl not able to run https (Google+ API)

May 2, 2015 588 views
PHP Apache API

I'm trying to pull the share count from Google+ using the code below:

function get_gplus_shares($url){
    $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "");
      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'] );

It is working fine on my local test environment, but not working on my live environment. I've installed php_curl using sudo apt-get install curl and sudo apt-get install php5-curl, which is working fine. Also added the cacert.pem by sudo wget -O /usr/lib/ssl/certs/cacert.pem. But doesn't seem to work. I really don't know where to proceed with this.

1 comment
  • Just saw another error, not sure if related to this.

    [ssl:error] [pid 20743] AH02032: Hostname IP-ADDRESS provided via SNI and hostname provided via HTTP are different

Be the first one to answer this question.