Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google calendar api Error 400 - Invalid resource id value

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);
}
like image 394
RomHill Avatar asked Oct 23 '25 21:10

RomHill


2 Answers

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

like image 153
JJP Avatar answered Oct 26 '25 22:10

JJP


You should encode your id as base32

$encoded = bin2hex( $booking['id'] );

To Decode

$decoded = hex2bin( $encoded );
like image 31
AlperXX Avatar answered Oct 26 '25 23:10

AlperXX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!