title: Google drive Upload returns - (403) Insufficient Permission
body: <p>I am trying to upload files to google drive using service account, but i am getting error like</p>
  
  <blockquote>
    <p>(403) Insufficient Permission error</p>
  </blockquote>
  
  <p>Although fetching list of files from drive is working fine.</p>
  
  <pre><code>require_once 'google-api-php-client-master/src/Google/autoload.php';
  require_once 'google-api-php-client-master/src/Google/Service.php';
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setAuthConfigFile('client_secrets.json');
  $service_account_name = '251181790499-1en2vs6jjovga1egu15tphm1m7g44m60@developer.gserviceaccount.com';
  $key_file_location = 'key.p12'; //key.p12
  
  $key = file_get_contents($key_file_location);;
  
  if (isset($_SESSION['access_token']) &amp;&amp; $_SESSION['access_token']) {
      $client-&gt;setAccessToken($_SESSION['access_token']);
      //$client-&gt;addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
      //$client-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
      $cred = new Google_Auth_AssertionCredentials(
      $service_account_name,
      array('https://www.googleapis.com/auth/drive'),
      $key);
  
      $client-&gt;setAssertionCredentials($cred);
      $client-&gt;setAccessType("offline");
  
      $file = new Google_Service_Drive_DriveFile();
      $file-&gt;setTitle(uniqid().'.jpg');
      $file-&gt;setDescription('A test document');
      $file-&gt;setMimeType('image/jpeg');
  
      $data = file_get_contents('a.jpg');
  
      $service = new Google_Service_Drive($client);
      $createdFile = $service-&gt;files-&gt;insert($file, array(
            'data' =&gt; $data,
            'mimeType' =&gt; 'image/jpeg',
            'uploadType' =&gt; 'multipart'
          ));
  
      print_r($createdFile);
  
  } 
  else
  {
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/googledrive/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
  }
  </code></pre>
  
  <p>I have reviewed similar questions in forum and tried suggestions but nothing seems to work.</p>
  
  <p>Is there anything wrong with code?</p>