title: Problems implementing service account with google-api-php-client
body: <p>This seemed to fix itself... after an hour or so I hit F5 and it worked, I could see a list of book titles.</p>
  
  <p>So I copied the file and modified it in order to get a list of all users    </p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  
  session_start();
  include_once "templates/base.php";
  
  set_include_path("../src/" . PATH_SEPARATOR . get_include_path());
  require_once 'Google/Client.php';
  require_once 'Google/Service/Directory.php';
  
  $client_id = '118xxx.apps.googleusercontent.com';
  $service_account_name = '118xxx@developer.gserviceaccount.com';
  $key_file_location = '/Path/ServiceAccount-privatekey.p12';
  
  echo pageHeader("Service Account Access");
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Client_Library_Examples");
  $service = new Google_Service_Directory($client);
  
  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/admin.directory.user.readonly'),
      $key
  );
  $cred-&gt;sub = "adminUser@googleAppsDomain.com";
  $client-&gt;setAssertionCredentials($cred);
  if($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
    $client-&gt;getAuth()-&gt;refreshTokenWithAssertion($cred);
  }
  $_SESSION['service_token'] = $client-&gt;getAccessToken();
  
  $results = $service-&gt;users-&gt;listUsers();
  echo "&lt;h3&gt;Results Of Call:&lt;/h3&gt;";
  print_r($results);
  echo pageFooter(__FILE__);
  </code></pre>
  
  <p>However, when I run this code I get </p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'Google_Service_Exception' with
    message 'Error calling GET
    <a href="https://www.googleapis.com/admin/directory/v1/users" rel="nofollow">https://www.googleapis.com/admin/directory/v1/users</a>: (400) Bad
    Request' in
    /var/www/common/google-api-php-client-master/src/Google/Http/REST.php:80</p>
  </blockquote>
  
  <p>Thanks again for your insight.</p>