I have the following error when wanting to create an event in my calendar through PHP:
Argument 1 passed to Google_AuthHandler_Guzzle6AuthHandler :: __ construct () must implement interface Psr \ Cache \ CacheItemPoolInterface, instance of Google_Cache_Memory given, called in C: \ xxx \ Google \ AuthHandler \ AuthHandlerFactory.php online 38 and defined
My code is like this:
<?php
require_once 'xxx/xxx/googleApi/vendor/autoload.php';
require_once 'xxx/xxx/googleApi/src/Google/Service/Google_Service_Calendar.php';
$client = new Google_Client();
$client->setAuthConfig('xxx/xxx/googleApi/client_secret.json');
$client->setApplicationName("Name");
$client->setAccessType('offline');
$client->setRedirectUri('http://localhost/xxx/src/index.php?r=agenda/registrar');
$client->addScope("https://www.googleapis.com/auth/calendar");
$service = new Google_Service_Calendar($client);
// Load previously authorized credentials from a file.
$credentialsPath = expandHomeDirectory( 'XXX/XXX/googleApi/Agenda_token.json');
//$credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
if (file_exists($credentialsPath)) {
$accessToken = json_decode(file_get_contents($credentialsPath), true);
} else {
// Request authorization from the user.
$authUrl = $client->createAuthUrl();
printf("Open the following link in your browser:\n%s\n", $authUrl);
print 'Enter verification code: ';
$authCode = trim(fgets(STDIN));
// Exchange authorization code for an access token.
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
// Store the credentials to disk.
if(!file_exists(dirname($credentialsPath))) {
mkdir(dirname($credentialsPath), 0700, true);
}
file_put_contents($credentialsPath, json_encode($accessToken));
printf("Credentials saved to %s\n", $credentialsPath);
}
$client->setAccessToken($accessToken);
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Google I/O 2017',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'descripcion',
'start' => array(
'dateTime' => '2017-05-27T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2017-05-27T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'attendees' => array(
array('email' => '[email protected]'),
array('email' => '[email protected]'),
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
));
$calendarId = ' [email protected]';
$event = $service->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);
?>