title: Google Drive SDK downloadFile - What does it do?
body: <p>I am developing in Drupal and using the php code from the Google Drive SDK that is supposed to download a file:</p>
  
  <pre><code>/**
   * Download a file's content.
   *
   * @param Google_DriveService $service Drive API service instance.
   * @param File $file Drive File instance.
   * @return String The file's content if successful, null otherwise.
   */
  function downloadFile($service, $file) {
    $downloadUrl = $file-&gt;getDownloadUrl();
    if ($downloadUrl) {
      $request = new Google_HttpRequest($downloadUrl, 'GET', null, null);
      $httpRequest = Google_Client::$io-&gt;authenticatedRequest($request);
      if ($httpRequest-&gt;getResponseHttpCode() == 200) {
        return $httpRequest-&gt;getResponseBody();
      } else {
        // An error occurred.
        return null;
      }
    } else {
      // The file doesn't have any content stored on Drive.
      return null;
    }
  }
  </code></pre>
  
  <p>It is returning a successful response code of 200 but I cannot tell that it has actually done anything.  However, I can tell from observing my LAN connection status that something of the right size in bytes is being downloaded.  I just don't know where it is ending up.  I am using Acquia Dev Desktop so I am running the website on my PC, but I cannot find where in the website folder the downloaded file is ending up if it is indeed being stored.  I then tried another function that I found <a href="https://stackoverflow.com/questions/12156098/google-drive-api-download-file-http-respond-code-200-but-the-responsebody-is-em">here</a> and got similar results.  Can someone more familiar with this explain what is happening?</p>
  
  <pre><code>function GetFile($service, $fileId) {
     $fileVars = null;
     try {
        /*
         * Retrieve metadata for the file specified by $fileId.
         */
        $file = $service-&gt;files-&gt;get($fileId);
        $fileVars = get_object_vars($file);
  
        /*
         * Retrieve the file's content using download URL specified in metadata.
         */
        $downloadUrl = $file-&gt;getDownloadUrl();
        error_log('Download URL file from Drive: ' . $downloadUrl);
        if ($downloadUrl) {
           $request = new Google_HttpRequest($downloadUrl, 'GET', null, null);
           $httpRequest = Google_Client::$io-&gt;authenticatedRequest($request);
           error_log(print_r($httpRequest, 1));
  
           if ($httpRequest-&gt;getResponseHttpCode() == 200) {
              $content = $httpRequest-&gt;getResponseBody();
              $fileVars['content'] = $content?($content):'';
           } else {
              // An error occurred.
              return null;
           }
        } else {
           // The file doesn't have any content stored on Drive.
           return null;
        }
  
     } catch (apiServiceException $e) {
        /*
         * Log error and re-throw
         */
        error_log('Error retrieving file from Drive: ' . $e-&gt;getMessage());
        throw $e;
     }
     return json_encode($fileVars);
  }
  </code></pre>
  
  <p>This method returns the following results:</p>
  
  <pre><code>{"alternateLink":"https:\/\/docs.google.com\/file\/d\/0B6ahcE1NPpIaMTJzcFRLMnNiYU0\/edit?usp=drivesdk","appDataContents":false,"createdDate":"2013-12-05T21:05:03.026Z","defaultOpenWithLink":null,"description":"Flashum mp4","downloadUrl":"https:\/\/doc-0g-50-docs.googleusercontent.com\/docs\/securesc\/apic76cj8gku48a9ogarn9khpku0s46q\/gc9ck66nc600ebdk0ak9f58gkthnnacm\/1386345600000\/08295678552528470768\/15372451357194678536\/0B6ahcE1NPpIaMTJzcFRLMnNiYU0?h=16653014193614665626&amp;e=download&amp;gd=true","editable":true,"embedLink":"https:\/\/video.google.com\/get_player?ps=docs&amp;partnerid=30&amp;docid=0B6ahcE1NPpIaMTJzcFRLMnNiYU0&amp;BASE_URL=https:\/\/docs.google.com\/","etag":"\"maCRbN5nR56FjQPLihEiz9nzpho\/MTM4NjI3NzUwNDU1MA\"","explicitlyTrashed":null,"exportLinks":null,"fileExtension":"mp4","fileSize":"788456","headRevisionId":"0B6ahcE1NPpIaeVJ5b3RxdExvamlDdWNrcGFvWXdvaWg3VU5JPQ","iconLink":"https:\/\/ssl.gstatic.com\/docs\/doclist\/images\/icon_11_video_list.png","id":"0B6ahcE1NPpIaMTJzcFRLMnNiYU0","imageMediaMetadata":null,"indexableText":null,"kind":"drive#file","labels":{"hidden":false,"restricted":false,"starred":false,"trashed":false,"viewed":false},"lastModifyingUser":{"displayName":"C. David Young","isAuthenticatedUser":false,"kind":"drive#user","permissionId":"08295678552528470768","picture":{"url":"https:\/\/lh6.googleusercontent.com\/-tjPzr0pfd_4\/AAAAAAAAAAI\/AAAAAAAAAWc\/DZtQHXrxkgQ\/s64\/photo.jpg"}},"lastModifyingUserName":"C. David Young","lastViewedByMeDate":null,"md5Checksum":"00701d2dd7a1b99e8ebb68cf62305b0d","mimeType":"application\/video","modifiedByMeDate":null,"modifiedDate":"2013-12-05T21:05:04.550Z","openWithLinks":null,"originalFilename":"charlesdavidyoung@gmail.com@test.mp4","ownerNames":["C. David Young"],"owners":[{"displayName":"C. David Young","isAuthenticatedUser":false,"kind":"drive#user","permissionId":"08295678552528470768","picture":{"url":"https:\/\/lh6.googleusercontent.com\/-tjPzr0pfd_4\/AAAAAAAAAAI\/AAAAAAAAAWc\/DZtQHXrxkgQ\/s64\/photo.jpg"}}],"parents":[{"id":"0B6ahcE1NPpIaQlMyWFBPamZIeTA","isRoot":false,"kind":"drive#parentReference","parentLink":"https:\/\/www.googleapis.com\/drive\/v2\/files\/0B6ahcE1NPpIaQlMyWFBPamZIeTA","selfLink":"https:\/\/www.googleapis.com\/drive\/v2\/files\/0B6ahcE1NPpIaMTJzcFRLMnNiYU0\/parents\/0B6ahcE1NPpIaQlMyWFBPamZIeTA"}],"quotaBytesUsed":"788456","selfLink":"https:\/\/www.googleapis.com\/drive\/v2\/files\/0B6ahcE1NPpIaMTJzcFRLMnNiYU0","shared":true,"sharedWithMeDate":null,"thumbnail":null,"thumbnailLink":"https:\/\/lh4.googleusercontent.com\/Ja2DZ3vzXSTn7kY_xY8VmC2N7nCeBrbvnkr-lO4GbMuOmpETwLAYlaC7qr5fOpBTTQ=s220","title":"charlesdavidyoung@gmail.com@test.mp4","userPermission":{"additionalRoles":null,"authKey":null,"etag":"\"maCRbN5nR56FjQPLihEiz9nzpho\/8jq33BWTNkV1S9Wn1TTkFYEVpVc\"","id":"me","kind":"drive#permission","name":null,"photoLink":null,"role":"writer","selfLink":"https:\/\/www.googleapis.com\/drive\/v2\/files\/0B6ahcE1NPpIaMTJzcFRLMnNiYU0\/permissions\/me","type":"user","value":null,"withLink":null},"webContentLink":"https:\/\/docs.google.com\/uc?id=0B6ahcE1NPpIaMTJzcFRLMnNiYU0&amp;export=download","webViewLink":null,"writersCanShare":true,"copyable":true,"content":null}
  </code></pre>