As per 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 instead.
Is it possible to create shortcut to the file with Google Drive PHP Client v2 or anyhow simple with PHP.
I have tryed:
$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 ] ]);
I’m getting unknown parameter: 'shortcutDetails'
Advertisement
Answer
I believe your goal and situation as follows.
- You want to create new shortcut using googleapis for php.
- You have already been able to use Drive API.
In this case, I would like to propose to use setShortcutDetails()
in your script. When your script is modified, it becomes as follows.
Modified script:
$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);
- Please set
$parent_id
and$file_id
.