title: Google Calendar API v3 Insert Event
body: <p>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:
  <a href="https://developers.google.com/google-apps/calendar/v3/reference/events/insert" rel="nofollow">https://developers.google.com/google-apps/calendar/v3/reference/events/insert</a></p>
  
  <p>Here is the code:</p>
  
  <pre><code>$event = new Event();
  $event-&gt;setSummary('Appointment');
  $event-&gt;setLocation('Somewhere');
  $start = new EventDateTime();
  $start-&gt;setDateTime('2011-06-03T10:00:00.000-07:00');
  $event-&gt;setStart($start);
  $end = new EventDateTime();
  $end-&gt;setDateTime('2011-06-03T10:25:00.000-07:00');
  $event-&gt;setEnd($end);
  $attendee1 = new EventAttendee();
  $attendee1-&gt;setEmail('attendeeEmail');
  // ...
  $attendees = array($attendee1,
                 // ...
                );
  $event-&gt;attendees = $attendees;
  $createdEvent = $service-&gt;events-&gt;insert('primary', $event);
  
  echo $createdEvent-&gt;getId();
  </code></pre>
  
  <p>From my understanding I am suppose to replace <code>'primary'</code> with my google calendar code. I have done that, and replaced <code>'attendeeEmail'</code> 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. </p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>$calendarListEntry = new CalendarListEntry();
  $calendarListEntry-&gt;setId("calendarId");
  
  $createdCalendarListEntry = $service-&gt;calendarList-&gt;insert($calendarListEntry);
  
  echo $createdCalendarListEntry-&gt;getSummary();
  </code></pre>
  
  <p>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)</p>
  
  <p>SOLVED - Here is the correct code:</p>
  
  <pre><code>$event = new Google_Service_Calendar_Event();
  $event-&gt;setSummary('Appointment');
  $event-&gt;setLocation('Somewhere');
  $start = new Google_Service_Calendar_EventDateTime();
  $start-&gt;setDateTime('2011-06-03T10:00:00.000-07:00');
  $event-&gt;setStart($start);
  $end = new Google_Service_Calendar_EventDateTime();
  $end-&gt;setDateTime('2011-06-03T10:25:00.000-07:00');
  $event-&gt;setEnd($end);
  $attendee1 = new Google_Service_Calendar_EventAttendee();
  $attendee1-&gt;setEmail('email');
  // ...
  $attendees = array($attendee1
                 //, ...
                );
  $event-&gt;attendees = $attendees;
  $createdEvent = $service-&gt;events-&gt;insert('primary', $event);
  echo $createdEvent-&gt;getId();
  </code></pre>