How can I insert an event into a google calendar?
I am using this guide: https://developers.google.com/google-apps/calendar/v3/reference/events/insert
In the examples section, there is this php code:
$event = new Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
echo $createdEvent->getId();
But that gives me a fatal error because $service is undefined. Can anybody tell me how to initialize $service and make this stuff work?
In the newest version of Google API v3 PHP client you should use
$event = new Google_Event();
instead of
$event = new Event();
And also use
$start = new Google_EventDateTime();
instead of
$start = new EventDateTime();
And of course the require definitions are different, use this one:
require_once '../src/Google_Client.php';
require_once '../src/contrib/Google_CalendarService.php';
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