title: How to insert event to user google calendar using php?
body: <p>I have these following codes to insert to my specific google calendar. Well it very successful, but <strong>how to let user can add to their own calendar</strong>? Somebody can help me... My expected results was like user can login via google.... it's means that user can add to their own google calendar. Thanks.</p>
  
  <p><em>Codes to add to my specific calendar</em></p>
  
  <pre><code>require_once './vendor/google/apiclient/src/Google/autoload.php';
  
  $key_file_location = 'Calendar-96992da17e2dda.p12'; // key.p12 to create in the Google API console
  
  $client_id = '6094969424649-compute@developer.gserviceaccount.com';
  $service_account_name = 'testsd-440@studied-zephyr-117012.iam.gserviceaccount.com'; // Email Address in the console account
  
  if (strpos($client_id, "gserviceaccount") == false || !strlen($service_account_name) || !strlen($key_file_location)) {
      echo "no credentials were set.";
      exit;
  }
  
  /** We create service access ***/
  $client = new Google_Client();  
  
  /************************************************
  If we have an access token, we can carry on.  (Otherwise, we'll get one with the help of an  assertion credential.)
  Here we have to list the scopes manually. We also supply  the service account
   ************************************************/
  if (isset($_SESSION['service_token'])) {
          $client-&gt;setAccessToken($_SESSION['service_token']);
  }
  $key = file_get_contents($key_file_location);
  $cred = new Google_Auth_AssertionCredentials(
      $service_account_name,
  array('https://www.googleapis.com/auth/calendar'), // ou calendar_readonly
  $key
  );
  
  $client-&gt;setAssertionCredentials($cred);
  if ($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
      $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);
  }
  $_SESSION['service_token'] = $client-&gt;getAccessToken();
  
  
  
  // Get the API client and construct the service object.
  $service = new Google_Service_Calendar($client);
  
  
      /************* INSERT ****************/
  $event = new Google_Service_Calendar_Event(array(
    'summary' =&gt; 'My Summary',
    'location' =&gt; 'My Location',
    'description' =&gt; 'My Description',
    'start' =&gt; array(
      'dateTime' =&gt; '2015-12-31T09:09:00',
      'timeZone' =&gt; 'Asia/Singapore',
    ),
    'end' =&gt; array(
      'dateTime' =&gt; '2015-12-31T17:16:00',
      'timeZone' =&gt; 'Asia/Singapore',
    ),
    'attendees' =&gt; array(
      array('email' =&gt; 'abc@gmail.com'),
      array('email' =&gt; 'def@gmail.my'),
    ),
    'reminders' =&gt; array(
      'useDefault' =&gt; FALSE,
      'overrides' =&gt; array(
        array('method' =&gt; 'email', 'minutes' =&gt; 24 * 60),
        array('method' =&gt; 'popup', 'minutes' =&gt; 10),
      ),
    ),
  ));
  
  $events = $service-&gt;events-&gt;insert('primary', $event);
  printf('Event created: %s', $events-&gt;htmlLink);
  </code></pre>