在 Google 驱动器 API PHP 客户端 v2 中创建文件快捷方式

Create a shortcut to file in Google Drive API PHP Client v2

改为按照 Single-parenting behavior changes in Google Drive API, beginning Sept. 30, 2020, you will no longer be able to place a file in multiple parent folders. Now we should Create a shortcut to a Drive file

是否可以使用 Google Drive PHP Client v2 或 PHP.

创建文件的快捷方式?

我试过了:

$file = new \Google_Service_Drive_DriveFile();
$file->setName('Shortcut Name');
$file->setParents([$parent_id]);
$file->setMimeType('application/vnd.google-apps.shortcut');
$shortcut = $drive->files->create($file, [
  'shortcutDetails' => [
      'targetId' => $file_id
  ]
]);

我得到 unknown parameter: 'shortcutDetails'

我相信你的目标和情况如下。

  • 您想使用 googleapis 为 php 创建新的快捷方式。
  • 您已经可以使用云端硬盘 API。

在这种情况下,我建议在您的脚本中使用setShortcutDetails()。当你的脚本修改后,变成如下。

修改后的脚本:

$file = new \Google_Service_Drive_DriveFile();
$file->setName('Shortcut Name');
$file->setParents([$parent_id]);
$file->setMimeType('application/vnd.google-apps.shortcut');

$shortcutDetails = new \Google_Service_Drive_DriveFileShortcutDetails();
$shortcutDetails->setTargetId($file_id);
$file->setShortcutDetails($shortcutDetails);

$createdFile = $service->files->create($file);
  • 请设置$parent_id$file_id

参考文献: