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:
- Got the file metadata
- 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.
Using API v3 this appears to have been deprecated, and according to the docs you call files->get()
on the Drive Service with an array parameter of "alt" => "media"
to get the file itself rather than the metadata.
And their example was:
$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$content = $driveService->files->get($fileId, array(
'alt' => 'media' ));
I'm having trouble understanding how this works though and have trawled through the code but it didn't give much more info.
When you call get()
, what actually goes into $content
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 fopen
on? How would I save this file to disk?
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?