title: Google Calendar API with PHP – Service Account
body: <p>I've been trying for several days now to get a Google Calendar API up and running with absolutely no luck. I'm using PHP and a service account for authentication. I have followed this tutorial (<a href="http://www.daimto.com/google-calendar-api-with-php-service-account/" rel="nofollow">http://www.daimto.com/google-calendar-api-with-php-service-account/</a>) and the code below is from that tutorial.</p>
  
  <p>I have setup my developers console to allow the calendar API, and I have added the developers email address to the calendar share section.</p>
  
  <p>When I run this code, I just get a blank page - no error, no text of any kind, just a blank white page. I'm completely lost - any help would be much appreciated. Cheers</p>
  
  <pre><code>&lt;?php
  
  require 'vendor/autoload.php';
  session_start();        
  
  $client_id = '123456789-qwertyuiop.apps.googleusercontent.com';
  $Email_address = '123456789-qwertyuiop@developer.gserviceaccount.com';   
  $key_file_location = 'path_to_key/key.p12';     
  
  $client = new Google_Client();      
  $client-&gt;setApplicationName("Client_Library_Examples");
  $key = file_get_contents($key_file_location);    
  
  // separate additional scopes with a comma   
  $scopes ="https://www.googleapis.com/auth/calendar.readonly";   
  $cred = new Google_Auth_AssertionCredentials(    
      $Email_address,      
      array($scopes),     
      $key         
  );      
  $client-&gt;setAssertionCredentials($cred);
  if($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {        
      $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);       
  }       
  $service = new Google_Service_Calendar($client);    
  
  ?&gt;
  
  &lt;html&gt;&lt;body&gt;
  
  &lt;?php
  $calendarList  = $service-&gt;calendarList-&gt;listCalendarList();
  
  while(true) {
      foreach ($calendarList-&gt;getItems() as $calendarListEntry) {
  
          echo $calendarListEntry-&gt;getSummary()."&lt;br&gt;\n";
  
          // get events 
          $events = $service-&gt;events-&gt;listEvents($calendarListEntry-&gt;id);
  
          foreach ($events-&gt;getItems() as $event) {
              echo "-----".$event-&gt;getSummary()."&lt;br&gt;";
          }
      }
      $pageToken = $calendarList-&gt;getNextPageToken();
      if ($pageToken) {
          $optParams = array('pageToken' =&gt; $pageToken);
          $calendarList = $service-&gt;calendarList-&gt;listCalendarList($optParams);
      } else {
          break;
      }
  }
  
  ?&gt;
  </code></pre>