title: Google PHP Client API: Insufficient Permission
body: <p>I have PHP code that use Google PHP Client API to use Drive service.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  require_once 'Google/Client.php';
  require_once 'Google/Service/Drive.php';
  
  const CLIENT_ID = '[MYCLIENTID]';
  const SERVICE_ACCOUNT_NAME = '[MYSERVICEACCOUNID]';
  
  // Make sure you keep your key.p12 file in a secure location, and isn't
  // readable by others.
  const KEY_FILE = './[MYPRIVATEKEY].p12';
  
  // Load the key in PKCS 12 format (you need to download this from the
  // Google API Console when the service account was created.
  $client = new Google_Client();
  $client-&gt;setApplicationName("Google Drive Sample");
  
  $key = file_get_contents(KEY_FILE);
  $client-&gt;setClientId(CLIENT_ID);
  $client-&gt;setAssertionCredentials(new Google_Auth_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/drive'),
    $key)
  );
  
  $client-&gt;setClientId(CLIENT_ID);
  
  if ($client-&gt;getAuth()-&gt;isAccessTokenExpired()) {
    $client-&gt;getAuth()-&gt;refreshTokenWithAssertion();
  }
  
  // Get the json encoded access token.
  $token = $client-&gt;getAccessToken();
  
  echo "&lt;pre&gt;";
  $service = new Google_Service_Drive($client);
  $service-&gt;apps-&gt;listApps();
  echo "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>I had CLIENT_ID, SERVICE_ACCOUNT_NAME and KEY_FILE correctly installed. When I run the code I get the following error messages:</p>
  
  <pre><code>Fatal error:  Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/drive/v2/apps: (403) Insufficient Permission' in C:\xampp\htdocs\oauth\Google\Http\REST.php:79
  Stack trace:
  #0 C:\xampp\htdocs\oauth\Google\Http\REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
  #1 C:\xampp\htdocs\oauth\Google\Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
  #2 C:\xampp\htdocs\oauth\Google\Service\Resource.php(195): Google_Client-&gt;execute(Object(Google_Http_Request))
  #3 C:\xampp\htdocs\oauth\Google\Service\Drive.php(1281): Google_Service_Resource-&gt;call('list', Array, 'Google_Service_...')
  #4 C:\xampp\htdocs\oauth\drive_client.php(41): Google_Service_Drive_Apps_Resource-&gt;listApps()
  #5 {main}
    thrown in C:\xampp\htdocs\oauth\Google\Http\REST.php on line 79
  </code></pre>
  
  <p>What may be wrong with the code?</p>