Php 无法使用Google Drive API V3下载文件

Php 无法使用Google Drive API V3下载文件,php,codeigniter,google-api,google-drive-api,google-api-php-client,Php,Codeigniter,Google Api,Google Drive Api,Google Api Php Client,我面临“调用字符串上的成员函数getBody()”的问题 我正在使用以下代码 public function downloadFile($fileId , $name) { try { $content = $this->service->files->get($fileId, array("alt" => "media")); $outHandle = fopen(APPPATH .&quo

我面临“调用字符串上的成员函数getBody()”的问题 我正在使用以下代码

 public  function downloadFile($fileId , $name)
{
  try
  {
       $content = $this->service->files->get($fileId, array("alt" => "media"));
       $outHandle = fopen(APPPATH ."Downloads". "/" . $name , "w+");
       while (!$content->getBody()->eof()) {
            fwrite($outHandle, $content->getBody()->read(1024));
      }
       fclose($outHandle);
        return $outHandle;
    } catch (\Exception $e) {
  }

}

这个选项可能更简单一些

$file = $service->files->get($fileId, array('alt' => 'media'));
file_put_contents($file->name, $file->getBody());