I'm trying to insert an event with Google Calendar API PHP. I've got no error, i've got the $event->hmtlLink
, but when I go on, Google say me "This event doesn't exist".
Here is my code to get client and service:
putenv("GOOGLE_APPLICATION_CREDENTIALS=" . __DIR__ . "/private/credentials.json");
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(SCOPES);
$service = new Google_Service_Calendar($client);
$calendarId = "primary";
Here is the function I use to create an event:
function createEvent($eventId, $name, $equipe, $location, $description, $startTimeDate, $endTimeDate, $timeZone){
$startTimeDate = new DateTime($startTimeDate);
$startTimeDate = date_format($startTimeDate, DATE_ISO8601);
$endTimeDate = new DateTime($endTimeDate);
$endTimeDate = date_format($endTimeDate, DATE_ISO8601);
$event = new Google_Service_Calendar_Event(array(
'id' => $eventId,
'summary' => join('',array("[",$equipe,"] ",$name)),
'location' => $location,
'description' => $description,
'start' => array(
'dateTime' => $startTimeDate,
'timeZone' => $timeZone,
),
'end' => array(
'dateTime' => $endTimeDate,
'timeZone' => $timeZone,
),
));
global $service, $calendarId;
$event = $service->events->insert($calendarId, $event);
printf($event->htmlLink);
printf($event->status);
printf($event->created);
}
The 1st printf send me a good link, but on opening: event not existing
The 2nd send "confirmed"
The 3rd send the good dateTime
When I try to insert an event with the same id, I've got an error saying this id already exists. But nothing in the calendar...
Help me please ! Thank you.