title: "Invalid Credentials" when accessing BigQuery through PHP API using service account
body: <p>I'm attempting to access Big Query through Google's php API using a service account.</p>
  
  <pre><code>&lt;?php
  
  require_once '../google-api-php-client/src/Google_Client.php';
  require_once '../google-api-php-client/src/contrib/Google_BigqueryService.php';
  
  define("CLIENT_ID", 'removed-removed.apps.googleusercontent.com');
  define("SERVICE_ACCOUNT_NAME", 'removed-removed@developer.gserviceaccount.com');
  define("KEY_FILE", '../../../key.p12');
  
  define("PROJECT_ID", removed);
  
  $client = new Google_Client();
  
  $key = file_get_contents(KEY_FILE);
  
  $client-&gt;setAssertionCredentials(new Google_AssertionCredentials(
                  SERVICE_ACCOUNT_NAME,
                  array('https://www.googleapis.com/auth/prediction'),
                  $key)
  );
  
  $client-&gt;setClientId(CLIENT_ID);
  
  // Instantiate a new BigQuery Client 
  $service = new Google_BigqueryService($client);
  
  try
  {
      $service-&gt;tables-&gt;listTables(PROJECT_ID, "data");
  } catch (Exception $e)
  {
      echo $e-&gt;getMessage();
  }
  
  ?&gt;
  </code></pre>
  
  <blockquote>
    <p>Error calling GET
    <a href="https://www.googleapis.com/bigquery/v2/projects/removed/datasets/data/tables" rel="nofollow">https://www.googleapis.com/bigquery/v2/projects/removed/datasets/data/tables</a>:
    (401) Invalid Credentials</p>
  </blockquote>