title: Insert event into google calendar with php
body: <p>How can I insert an event into a google calendar?</p>
  
  <p>I am using this guide:
  <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>In the examples section, there is this php 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>But that gives me a fatal error because $service is undefined.
  Can anybody tell me how to initialize $service and make this stuff work? </p>