title: insufficient permission google drive api oauth2 in php
body: <p>I am trying to upload a file on google drive through PHP. I've created a project in the developer console, enabled the Drive API and added an OAuth 2.0 client ID.
  here is my code.</p>
  
  <pre><code>&lt;?php
   require_once __DIR__.'/vendor/autoload.php';
  
      session_start();
  
      $client = new Google_Client();
      $client-&gt;setAuthConfigFile('client_secret.json');
      $client-&gt;addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
      $client-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
  
      if (isset($_SESSION['access_token']) &amp;&amp; $_SESSION['access_token']) {
          $client-&gt;setAccessToken($_SESSION['access_token']);
          $drive_service = new Google_Service_Drive($client);
          $files_list = $drive_service-&gt;files-&gt;listFiles(array())-&gt;getFiles();
          echo "&lt;pre&gt;";
          print_r($files_list);
      } else {
          $redirect_uri = 'http://localhost/oauth2callback.php';
          header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
      }   
      $filename = "abc.txt";
      $file = new Google_Service_Drive_DriveFile();
      $file-&gt;setName($filename);
      $result = $drive_service-&gt;files-&gt;create($file, array(
    'data' =&gt; file_get_contents("abc.txt"),
    'mimeType' =&gt; 'application/octet-stream',
    'uploadType' =&gt; 'media'
  ));
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>Fatal error:  Uncaught exception 'Google_Service_Exception' with message '{
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "insufficientPermissions",
      "message": "Insufficient Permission"
     }
    ],
    "code": 403,
    "message": "Insufficient Permission"
   }
  }
  ' in D:\xampp\htdocs\vendor\google\apiclient\src\Google\Http\REST.php:118
  </code></pre>