title: Google API PHP Client - retrieve calendar list and events
body: <p>The documentation for google calendar api is out of date, I am unable to get even a simple calendar list. Here is my code so far.</p>
  
  <pre><code>&lt;?php
  require_once "includes/partials/_header.php";
  set_include_path(get_include_path() . '/google-api-php-client/src');
  
  $client_id = 'xxxx.apps.googleusercontent.com';
  $service_account = 'xxxx@developer.gserviceaccount.com';
  $p12 = 'xxxx-privatekey.p12';
  
  session_start();
  require_once 'Google/Client.php';
  require_once 'Google/Service/Calendar.php';
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Calendrier");
  
  if (isset($_SESSION['token'])) {
   $client-&gt;setAccessToken($_SESSION['token']);
  }
  
  $key = file_get_contents($p12);
  $client-&gt;setClientId($client_id);
  $cred = new Google_Auth_AssertionCredentials(
      $service_account,
      array('https://www.googleapis.com/auth/calendar'),
      $key);
  
  $client-&gt;setAssertionCredentials($cred);
  if($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
    $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);
  }
  $_SESSION['service_token'] = $client-&gt;getAccessToken();
  
  $cal = new Google_Service_Calendar($client);
  
  $events = $cal-&gt;calendarList-&gt;listCalendarList();
  echo "&lt;pre&gt;";
  print_r($events);
  echo"&lt;/pre&gt;";
  
  while(true) {
      foreach ($events-&gt;getItems() as $event) {
      echo $event-&gt;getSummary();
          print_r($event);
    }
    $pageToken = $events-&gt;getNextPageToken();
    if ($pageToken) {
      $optParams = array('pageToken' =&gt; $pageToken);
      $events = $service-&gt;calendarList-&gt;listCalendarList($optParams);
    } else {
      break;
    }
  }
  ?&gt;
  </code></pre>
  
  <p>I got a lot of this code from different sites because the docs were out of date, now I'm totally stuck as I've been googling all day. Any insight?</p>
  
  <p>All i get so far is a response like this with no "items"</p>
  
  <pre><code>Google_Service_Calendar_CalendarList Object
  (
      [etag] =&gt; "xxxxxxxxxxxx"
      [itemsType:protected] =&gt; Google_Service_Calendar_CalendarListEntry
      [itemsDataType:protected] =&gt; array
      [kind] =&gt; calendar#calendarList
      [nextPageToken] =&gt; 
      [nextSyncToken] =&gt; 00001401741798955000
      [collection_key:protected] =&gt; items
      [modelData:protected] =&gt; Array
          (
              [items] =&gt; Array
                  (
                  )
  
          )
  
      [processed:protected] =&gt; Array
          (
          )
  
  )
  </code></pre>