3
votes

This is the code I have written to fetch the calendar events from Google Calendar. On running this in localhost, it takes the permission from the user but shows

Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in D:\wamp\www\google-api-php-client-2.0.0-RC4\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

( ! ) GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html) in D:\wamp\www\google-api-php-client-2.0.0-RC4\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

I tried adding cacert.pem path's in php.ini and other mentioned things over other forums. Nothing worked. I tried putting the file online in a server(Centos). Installed composer too. But there, when I try to load the page nothing shows.

As far as I think, there the autoload.php inside vendor of Google api package does not return anything.

return ComposerAutoloaderInitd82ee48119182e2321ebd694e70287c2::getLoader();

Where am I going wrong? Or, is there something wrong with the code?

session_start();
require_once './google-api-php-client-2.0.0-RC4/vendor/autoload.php';
set_include_path(get_include_path() . PATH_SEPARATOR . './google-api-php-client-2.0.0-RC4/src');
$google_client_id = '...';
$google_client_secret = '...';
$google_redirect_uri = 'http://localhost/gapicc.php';
$client = new Google_Client();
$client -> setApplicationName('Sample');
$client -> setClientid($google_client_id);
$client -> setClientSecret($google_client_secret);
$client -> setRedirectUri($google_redirect_uri);
$client -> setAccessType('online');
$client -> setScopes(Google_Service_Calendar::CALENDAR);
$googleImportUrl = $client -> createAuthUrl();
if(isset($_GET['code']))
{
    $auth_code = $_GET['code'];
    $client->authenticate($_GET['code']);
    $access_token = $client->getAccessToken();
    $calendar_service = new Google_Service_Calendar($client);
    $calendar_list = $calendar_service->calendarList->listCalendarList(array())->getItems();
    echo json_encode($calendar_list);
}

echo filter_var($googleImportUrl, FILTER_SANITIZE_URL); // Path where I am heading the user when he clicks "Import Google Calendar"

1
Have you looked at the PHP Quickstart for Google Calendar API? Is the Calendar API enabled in your developer console?adjuremods

1 Answers

0
votes

It's ok to use URL without SSL as redirect URL. localhost is also allowed. The problem probably in auth or token URL

  1. Check Restrictions of you key here https://console.developers.google.com/apis/credentials

  2. Try to use credentials.json from there instead set ClientID and ClientSecret. It also has auth_uri and token_uri.

    For this use fresh google API calendar quickstart https://github.com/gsuitedevs/php-samples/tree/master/calendar/quickstart as help with all steps.

    with the last version of google API (2.2.2 now) https://github.com/googleapis/google-api-php-client/releases