title: Download CSV file using Google Drive V3(V2 works perfect) throws error 403
body: <p>I m using <strong>DRIVE V2</strong> WITH <strong>Service Account to download CSV file</strong>,This one is working fine. I want to migrate DRIVE V2 to DRIVE V3 .So i changed my script as per below google documents</p>
  
  <p><strong><a href="https://developers.google.com/drive/v3/web/manage-downloads#downloading_a_file" rel="nofollow noreferrer">I. Download a file in drive V3</a></strong></p>
  
  <p><strong><a href="https://github.com/google/google-api-php-client/releases/tag/1.1.7" rel="nofollow noreferrer">PHP Library</a> &amp; <a href="https://gist.github.com/bshaffer/9bb2cdccd315880ab52f" rel="nofollow noreferrer">Drive API V3</a> used in this sample:</strong></p>
  
  <p><strong>1.Sample script download CSV file using Drive V3</strong></p>
  
  <p><strong>Method used: Using alt=media</strong> </p>
  
  <p><strong>Reason: this method only available in DRIVE V3</strong></p>
  
  <pre><code>&lt;?php
  set_include_path( get_include_path() . PATH_SEPARATOR . 'Google' );
  require_once 'Google/autoload.php';
  require_once 'Google/Client.php';
  require_once 'Google/Service/Drive.php';
  try{
      //Get service document
      $service = get_service_document();
      //Download a csv file
      $data = $service-&gt;files-&gt;get("FILE ID", array( 'alt' =&gt; 'media'));
     print_r($data);
  }
  catch(Exception $e){
      print_r($e-&gt;getMessage());
  }
  //function to get service
  function get_service_document(){
      $userstamp='user@example.com';
  
  //Enable below two lines if let know the clientid,tokens,etc.,
      $driveService=buildServiceDrive($userstamp,"SERVICE_ACCOUNT","https://www.googleapis.com/auth/drive","KEY.p12");
      return $driveService;
  }
  //building service
  function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
      $key = file_get_contents($service_filename);
      $auth = new Google_Auth_AssertionCredentials(
          $service_id,
          array($scope),
          $key);
      $auth-&gt;sub = $userEmail;
      $client = new Google_Client();
      $client-&gt;setAssertionCredentials($auth);
      return new Google_Service_Drive($client);
  }
  </code></pre>
  
  <p><strong>RESULT:</strong>
  I got the below issue </p>
  
  <pre><code>Error calling GET https://www.googleapis.com/drive/v3/files/0B5pkfK_IBDxjeHlTTDFFY01CXzQ?alt=media: (302)
  Moved Temporarily
  The document has moved here.
  </code></pre>
  
  <p>After clicked here. I saw below error.</p>
  
  <pre><code>{
   "error": {
    "errors": [
     {
      "domain": "usageLimits",
      "reason": "dailyLimitExceededUnreg",
      "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
      "extendedHelp": "https://code.google.com/apis/console"
     }
    ],
    "code": 403,
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
   }
  }
  </code></pre>
  
  <p><strong>II. <a href="https://developers.google.com/drive/v2/web/manage-downloads#alternate_method_using_downloadurl" rel="nofollow noreferrer">Download a file in Drive V2</a></strong></p>
  
  <p>I used alternate method to download CSV file from drive.</p>
  
  <p><strong><a href="https://github.com/google/google-api-php-client/releases/tag/1.1.7" rel="nofollow noreferrer">PHP Library</a> &amp; <a href="https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Drive.php" rel="nofollow noreferrer">Drive API V2</a> used in this sample:</strong></p>
  
  <p><strong>2.Sample Script download CSV file using Drive V2</strong></p>
  
  <p><strong>Method used :  Alternate method: using downloadUrl</strong></p>
  
  <pre><code>&lt;?php
  set_include_path( get_include_path() . PATH_SEPARATOR . 'Google' );
  require_once 'Google/autoload.php';
  require_once 'Google/Client.php';
  require_once 'Google/Service/Drive.php';
  try{
  
      //Get service document
      $service = get_service_document();
      $data = $service-&gt;files-&gt;get("FILE ID");
      $url=$data-&gt;downloadUrl;
      $data=downloadFile($service,$url);
      print_r($data);
  }
  catch(Exception $e){
      print_r($e-&gt;getMessage());
  }
  
  //Alternate method using download URL
  function downloadFile($service, $downloadUrl)
  {
      if ($downloadUrl) {
          $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
          $httpRequest = $service-&gt;getClient()-&gt;getAuth()-&gt;authenticatedRequest($request);
          if ($httpRequest-&gt;getResponseHttpCode() == 200) {
              return $httpRequest-&gt;getResponseBody();
          } else {
              echo "errr";
              return null;
          }
      } else {
          echo "empty";
          return null;
      }
  }
  //function to get service
  function get_service_document(){
  $driveService =buildServiceDrive(user@example.com',"SERVICE-ACCOUNT","https://www.googleapis.com/auth/drive","KEY.p12");
      return $driveService;
  }
  //building service
  function buildServiceDrive($userEmail,$service_id,$scope,$service_filename) {
      $key = file_get_contents($service_filename);
      $auth = new Google_Auth_AssertionCredentials(
          $service_id,
          array($scope),
          $key);
      $auth-&gt;sub = $userEmail;
      $client = new Google_Client();
      $client-&gt;setAssertionCredentials($auth);
      return new Google_Service_Drive($client);
  }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <p>i got CSV file records, working fine
  <a href="https://i.stack.imgur.com/zBYM2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zBYM2.png" alt="enter image description here"></a></p>
  
  <p>Plz help me resolve to download a CSV file using G DRIVE V3. Is there any regression or functions lagging b/w V2, V3?</p>