I am having difficulties understanding the insertion process for the google calendar API. I have the code they gave in their example, but it is not working when I use it, the page draws a blank (if I echo text below it does not show). Here is a link to the page I am referring to: https://developers.google.com/google-apps/calendar/v3/reference/events/insert
Here is the 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();
From my understanding I am suppose to replace 'primary'
with my google calendar code. I have done that, and replaced 'attendeeEmail'
with the calendar owner email address, removed the extra comma, and I am not getting any response. The referencing page links to 'deprecated code' so I am unsure if what I am using is the most up to date example.
Is there a working example out there that I can reference? Or is there something wrong with what I am doing? Any advise is greatly appreciated.
Final question: This is all linked under the 'Events -> Insert' directory. There is also a 'Calendars -> Insert' and a 'CalendarList -> Insert' directory. The 'CalendarList -> Insert' says that I am to use this code to insert into a users Calendar:
$calendarListEntry = new CalendarListEntry();
$calendarListEntry->setId("calendarId");
$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry);
echo $createdCalendarListEntry->getSummary();
Should I be using this instead? If so where can I find an example or tutorial to do use this? (How do I insert startDateTime, endDateTime, timeZone, etc)
SOLVED - Here is the correct code:
$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('email');
// ...
$attendees = array($attendee1
//, ...
);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
echo $createdEvent->getId();