APD Toronto
asked on
Fatal Error with Google API
Hi Experts,
This is a weird issue. I have been developing a small PHP App on my Dev Server (IIS7) with Google Calendar API, then launched it on my live Server (IIS8). At that time, the connection to the API worked from both servers, which was a month back.
While the connection from my Live Server continues to work, on my Dev Server I get
You can see a working version on my Live Server here:
http://crm-cor.aces-project.com/utilities/google_calendar/index.php?ajax_call=free-slots&first_date=2018-02-19&duration=90
A success result is a JSON object.
The error suggest a SSL issue, but as you can see by the URL, https is not used.
Actually for my Live Server I have support, and they were supposed to replace cacert.pem under Plesk. On my Dev, i don't have Plesk, and did not need to replace cacert.pem, or don't know how
Thank you
This is a weird issue. I have been developing a small PHP App on my Dev Server (IIS7) with Google Calendar API, then launched it on my live Server (IIS8). At that time, the connection to the API worked from both servers, which was a month back.
While the connection from my Live Server continues to work, on my Dev Server I get
PHP Fatal error: Uncaught GuzzleHttp\Ring\Exception\RingException: Error creating resource: [message] fopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
[file] C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\ringphp\src\Client\StreamHandler.php
[line] 406
[message] fopen(): Failed to enable crypto
[file] C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\ringphp\src\Client\StreamHandler.php
[line] 406
[message] fopen(https://www.googleapis.com/oauth2/v4/token): failed to open stream: operation failed
[file] C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\ringphp\src\Client\StreamHandler.php
[line] 406
[message] Undefined variable: http_response_header
[file] C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\ringphp\src\Client\StreamHandler.php
[line] 407 in C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\ringph in C:\inetpub\wwwroot\CRM_COR\utilities\google_calendar\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 51
You can see a working version on my Live Server here:
http://crm-cor.aces-project.com/utilities/google_calendar/index.php?ajax_call=free-slots&first_date=2018-02-19&duration=90
A success result is a JSON object.
The error suggest a SSL issue, but as you can see by the URL, https is not used.
Actually for my Live Server I have support, and they were supposed to replace cacert.pem under Plesk. On my Dev, i don't have Plesk, and did not need to replace cacert.pem, or don't know how
Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have been to those links before, but the problem is I dont know to do with the cacert.pem when I download it. How do I add it to my web server and/or browser?
Put it somewhere on your server that you have given access to the internet user. If you put it outside of the www folder, make sure the intenet user has access. You can put it inside the www and then access it that way.
For Authorize.net as example you can see on line 18 of this code. This is the httpclient.php file. You probably have something similar. I think I always had problems and downloaded the pem file from hax, then added the intermediate cert from my provider to the pem file.
For Authorize.net as example you can see on line 18 of this code. This is the httpclient.php file. You probably have something similar. I think I always had problems and downloaded the pem file from hax, then added the intermediate cert from my provider to the pem file.
public function _sendRequest($xmlRequest)
{
$xmlResponse = "";
$post_url = $this->_getPostUrl();
$curl_request = curl_init($post_url);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($curl_request, CURLOPT_HEADER, 0);
curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
$this->logger->info(sprintf(" Url: %s", $post_url));
// Do not log requests that could contain CC info.
$this->logger->info(sprintf("Request to AnetApi: \n%s", $xmlRequest));
if ($this->VERIFY_PEER) {
curl_setopt($curl_request, CURLOPT_CAINFO, dirname(dirname(__FILE__)) . '/../../ssl/cert.pem');
} else {
$this->logger->error("Invalid SSL option for the request");
return false;
}
if (preg_match('/xml/',$post_url)) {
curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
// file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND);
$this->logger->info("Sending 'XML' Request type");
}
try
{
$this->logger->info("Sending http request via Curl");
$xmlResponse = curl_exec($curl_request);
$this->logger->info("Response from AnetApi: $xmlResponse");
} catch (\Exception $ex)
{
$errorMessage = sprintf("\n%s:Error making http request via curl: Code:'%s', Message:'%s', Trace:'%s', File:'%s':'%s'",
$this->now(), $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), $ex->getFile(), $ex->getLine() );
$this->logger->error($errorMessage);
}
if ($this->logger && $this->logger->getLogFile()) {
if ($curl_error = curl_error($curl_request)) {
$this->logger->error("CURL ERROR: $curl_error");
}
}
curl_close($curl_request);
return $xmlResponse;
}
ASKER
Remember the curl is in the Google API library. If I add li 18 from your code before I load Google, will that work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!!!
ASKER