I'm migrating My Drive to Team Drives and I have a few thousand folders to move, each one into its own Drive. I have some php code using google/apiclient:2.7
that can use the Google Drive API to create the Drives. I now need to move the folders and am getting errors while doing so.
My code is authenticating using OAuth for a user that has the proper permissions and is able to migrate a folder using the Google UI. When I use the php code to move a file into a team drive, it moves successfully. When I try to do so with a folder I get an error message.
code:
//$files is an array where the values are the google id's
$id = $files['File adI3O'];
$parentId = $files['Drive'];
$google_file = new Google_Service_Drive_DriveFile();
//The parents field is not directly writable in update requests. Use the addParents and removeParents parameters instead.
//$google_file->setParents([$parentId]);
/** @var Google_Service_Drive $service */
$response = $service->files->update($id, $google_file, $service->optParams([
'supportsAllDrives' => true,
'addParents' => $parentId,
//'useDomainAdminAccess' => true,//(update) unknown parameter: 'useDomainAdminAccess'
]));
(The removeParents paramter is absent from my code. I was successful moving the file without using the removeParents paramter so it must not be needed.)
error message when setting $id to $files['Folder 69daL']
:
Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDrivesFolderMoveInNotSupported",
"message": "Moving folders into shared drives is not supported."
}
],
"code": 403,
"message": "Moving folders into shared drives is not supported."
}
}
Google Documentation indicates that with proper permissions a Folder can be moved into a Shared Drive. How can it be done using the Google Drive API?