Saving images from Google Drive via API
<p>I have followed <a href="https://developers.google.com/drive/v3/web/quickstart/php" rel="nofollow noreferrer">this tutorial</a> and everything is working, I can see the list of names and ids.</p>

<p>When I try to save this image on my server, the saved file is empty. I run this script from the command line.</p>

<pre><code>// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Drive($client);

// Print the names and IDs for up to 10 files.
$optParams = array(
  'pageSize' =&gt; 1,
  'fields' =&gt; 'nextPageToken, files(id, name)'
);
$results = $service-&gt;files-&gt;listFiles($optParams);

if (count($results-&gt;getFiles()) == 0) {
  print "No files found.\n";
} else {
  print "Files:\n";
  foreach ($results-&gt;getFiles() as $file) {
    printf("%s (%s)\n", $file-&gt;getName(), $file-&gt;getId());

  $fileIdr = $file-&gt;getId();
  }
 // $content = $service-&gt;files-&gt;export($fileIdr, 'image/jpeg', array('alt' =&gt; 'media' ));
  $content = $service-&gt;files-&gt;get($fileIdr, array('alt' =&gt; 'media' ));

    var_dump($content);

  $zdjecie = '/home/bachus03/domains/bachus03.vot.pl/public_html/fb/public/test.jpg';
  file_put_contents($zdjecie, $content);
</code></pre>