Kira
Kira

Reputation: 569

Google Calendar Events API throwing error

I have my application authenticated using OAuth - and I've tested it with the calendar API. Everything works. I also used the "quick add" method for the events API, and that worked fine. But when I tried to insert using the following code

$event = new Event();
$event->setSummary('hello there');
$event->setLocation('America/Los_Angeles');
$start = new EventDateTime();
$start->setDateTime('2012-04-19');
$event->setStart($start);
$createdEvent = $cal->events->insert('[email protected]', $event);

I get the following error:

Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling POST
https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyBddYIgnZJrXHuT8gvX-0tEypxsycw99rA: (400) Bad Request' in C:\xampp\htdocs\uis\google-api-php-client\src\io\apiREST.php:86 Stack trace: #0 C:\xampp\htdocs\uis\google-api-php-client\src\io\apiREST.php(56): apiREST::decodeHttpResponse(Object(apiHttpRequest)) #1 C:\xampp\htdocs\uis\google-api-php-client\src\service\apiServiceResource.php(187): apiREST::execute(Object(apiServiceRequest)) #2 C:\xampp\htdocs\uis\google-api-php-client\src\contrib\apiCalendarService.php(493): apiServiceResource->__call('insert', Array) #3 C:\xampp\htdocs\uis\google-api-php-client\examples\calendar\cal.php(44): EventsServiceResource->insert('paine1591@gmail...', Object(Event)) #4 {main} thrown in C:\xampp\htdocs\uis\google-api-php-client\src\io\apiREST.php on line 86

with [email protected] being the ID of my calendar. It works for everything else.

What am I doing wrong?

Upvotes: 0

Views: 1492

Answers (1)

Chirag Shah
Chirag Shah

Reputation: 3674

It appears that you're not setting the attendees of the event.

Example:

$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->end = $end;

$attendee1 = new EventAttendee();
$attendee1->email = 'attendeeEmail';

$attendees = array($attendee1, ...);
$event->attendees = $attendees;

Upvotes: 2

Related Questions