title: Google Drive V3, Google API client 2.0 - batch upload is failing
body: <p>Batch upload fails using Google Drive V3 with master branch of API (v2.0).</p>
  
  <p>I've modified <a href="https://github.com/google/google-api-php-client/blob/master/examples/batch.php" rel="nofollow">https://github.com/google/google-api-php-client/blob/master/examples/batch.php</a> with service account credentials.</p>
  
  <p>The code:</p>
  
  <pre><code>include_once __DIR__ . '/../vendor/autoload.php';
  include_once "templates/base.php";
  
  echo pageHeader("Batching Queries");
  
  // USE TRUE OR FALSE TO TOGGLE BETWEEN BATCHED AND SEQUENTIAL UPLOADS.
  $useBatch = true;
  
  $client = new Google_Client();
  $client-&gt;setScopes([
      'https://www.googleapis.com/auth/drive',
  ]);
  if ($credentials_file = checkServiceAccountCredentialsFile()) {
    // set the location manually
    $client-&gt;setAuthConfig($credentials_file);
  } elseif (getenv('GOOGLE_APPLICATION_CREDENTIALS')) {
    // use the application default credentials
    $client-&gt;useApplicationDefaultCredentials();
  } else {
    exit;
  }
  $client-&gt;setSubject('some@email.com');
  $service = new Google_Service_Drive($client);
  $client-&gt;setUseBatch($useBatch);
  
  if ($useBatch) {
      $batch = $service-&gt;createBatch();
  }
  
  $folder = new Google_Service_Drive_DriveFile([
    'name' =&gt; 'Invoices',
    'mimeType' =&gt; 'application/vnd.google-apps.folder'
  ]);
  
  $req = $service-&gt;files-&gt;create($folder, [
    'fields' =&gt; 'id'
  ]);
  
  if ($useBatch) {
      $result = $batch-&gt;add($req, 'newfolder');
      $folder = $batch-&gt;execute()['response-newfolder'];
      $newFolderId = $folder-&gt;id;
  } else {
      $newFolderId = $req-&gt;id;
  }
  
  $uploadIDs = null;
  
  if ($useBatch) {
      $batch = $service-&gt;createBatch();
  }
  
  for ($i=1;$i&lt;=3;$i++) {
      $file = new Google_Service_Drive_DriveFile([
          'name' =&gt; $i . '.jpg',
          'mimeType' =&gt; 'image/jpeg',
          'parents' =&gt; [$newFolderId],
      ]);
  
      $req = $service-&gt;files-&gt;create($file, [
          'data' =&gt; file_get_contents('img/'.$i.'.jpg'),
          'mimeType' =&gt; 'image/jpeg',
          'uploadType' =&gt; 'media',
          'fields' =&gt; 'id',
      ]);
  
      if ($useBatch) {
          $batch-&gt;add($req, $i);
      } else {
          $uploadIDs[] = $req-&gt;id;
      }
  }
  
  if ($useBatch) {
      $results = $batch-&gt;execute();
  } else {
      print_r($uploadIDs);
  }
  </code></pre>
  
  <p>The code above will fail with "Not Found" after running last $results = $batch->execute();  (folder Invoices will be created successfully).</p>
  
  <p>With <code>$useBatch = false</code> everything works as expected - a folder is created with three files in it.</p>
  
  <p>Why is it crashing on batch upload?</p>
  
  <p>Thanks!</p>