I want to insert events in Google calendar through the API using a Symfony command (batch).
When I insert an event with an ID like "event01487", it throws me the following errors : "code": 400, "message": "Invalid resource id value."
This id is unique as no events have been inserted - it didn't even insert it once. The id seems to fit the Google requirements...
Do you have any idea why I got this ?
foreach($bookingsToSync as $booking){
$event = new Google_Service_Calendar_Event();
$event->setId($booking['id']);
$event->setSummary($booking['title']);
$event->setDescription($booking['description']);
$start = new \Google_Service_Calendar_EventDateTime();
$start->setDateTime($booking['startDate']->format(DateTime::ATOM));
$event->setStart($start);
$end = new \Google_Service_Calendar_EventDateTime();
$end->setDateTime($booking['endDate']->format(DateTime::ATOM));
$event->setEnd($end);
$output->writeln($event->getId());
$service->events->insert($calendarId, $event);
}
You have to follow the guidelines defined here : https://developers.google.com/google-apps/calendar/v3/reference/events/insert
Basically, the id has to be between 5 and 1024 characters and be composed from characters in this alphabet : 0123456789abcdefghijklmnopqrstuv
You should encode your id as base32
$encoded = bin2hex( $booking['id'] );
To Decode
$decoded = hex2bin( $encoded );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With