title: Google Drive API v3 - downloading files in PHP
body: <p>I'm trying to understand the download flow for the Google Drive API v3 using PHP. Using the API v2 to download a file I:</p>
  
  <ul>
  <li>Got the file metadata</li>
  <li>Used the downloadUrl parameter to get a direct link to the file, attached an oAuth token to it and made a GET request to that.</li>
  </ul>
  
  <p>Using API v3 this appears to have been deprecated, and according to the <a href="https://developers.google.com/drive/v3/web/manage-downloads" rel="noreferrer">docs</a> you call <code>files-&gt;get()</code> on the Drive Service with an array parameter of <code>"alt" =&gt; "media"</code> to get the file itself rather than the metadata.</p>
  
  <p>And their example was:</p>
  
  <pre><code>$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
  $content = $driveService-&gt;files-&gt;get($fileId, array(
  'alt' =&gt; 'media' ));
  </code></pre>
  
  <p>I'm having trouble understanding how this works though and have trawled through the code but it didn't give much more info.</p>
  
  <p>When you call <code>get()</code>, what actually goes into <code>$content</code> in the example? Is it the contents of the file (in which case this seems troublesome when dealing with large files - surely you'll get out of memory?!) or is it some type of stream reference that I can call <code>fopen</code> on? How would I save this file to disk?</p>
  
  <p>The documentation doesn't really go into any detail about what happens when you make that API call, it just says it performs a file download?</p>