title: Google Api Php client - Spreadsheets permission error
body: <p>I am using Google PHP client to access spreadsheet data. </p>
  
  <p>I getting this fatal error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "code": 403, "message": "The caller does not have permission", "errors": [ { "message": "The caller does not have permission", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>  $client = new Google_Client();
    $client-&gt;setApplicationName("Google spreadsheets");
    $client-&gt;setDeveloperKey("xxxxx");
    $client-&gt;setScopes(array('https://www.googleapis.com/auth/drive',    
    'https://www.googleapis.com/auth/spreadsheets.readonly',     
    'https://www.googleapis.com/auth/drive.file'));
  
    $service = new Google_Service_Sheets($client);
  
    $range = 'Class Data!A2:E';
    $response = $service-&gt;spreadsheets_values-&gt;get($sheetid, $range);
    $values = $response-&gt;getValues();
  
    if (count($values) == 0) {
        print "No data found.\n";
    } else {
      print "Name, Major:\n";
      foreach ($values as $row) {
       // Print columns A and E, which correspond to indices 0 and 4.
       printf("%s, %s\n", $row[0], $row[4]);
      }
    }
  </code></pre>
  
  <p>How to fix this?</p>