【问题标题】:Getting an image using the Google Drive PHP API使用 Google Drive PHP API 获取图像
【发布时间】:2021-08-06 01:54:34
【问题描述】:

我正在尝试使用 PHP API 检索位于 Google Drive 中的图像。授权有效,但我似乎无法弄清楚如何让图像文件将其放置在文件夹中。我在网上没有找到任何结果。

正在使用

$driveService->files->get($fileId),

其中 $driveService 是 Google_Service_Drive 类。

然后我尝试使用 webContentLink 来下载文件,但 webContentLink 被设置为 null。该图像位于一个文件夹中,该文件夹具有授予服务帐户的编辑权限,该服务帐户用于访问图像。

【问题讨论】:

标签: php google-api google-drive-api google-api-php-client


【解决方案1】:

webContentLink 仅适用于二进制文件。如果您使用的是 file.get,您只需编写 get 正文并将其写入文件。

$file = $service->files->get($fileId, array('alt' => 'media'));
file_put_contents("hello.pdf",$file->getBody());

【讨论】:

  • 请编辑您的问题并包含您的代码
  • 我的错,这是 Intelliphense 的错误,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-14
  • 2020-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
相关资源
最近更新 更多