0
votes

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?

1
Download the file and then upload it again to the team drive.DaImTo
So your final intention is to move folders which contain files to a different drive (in this case a shared drive) using Drive API right?Mateo Randwolf
Yes @MateoRandwolf. Do you know if this is possible with the API?watermelon
@DaImTo I have thousands of folders to create drives for, each containing a number of subfolders with files. I could write code to move them one at a time but dont have the time to do so.tzvi

1 Answers

2
votes

I think, like the error message says, it is not supported. The documentation says that it is possible, but does not say it is possible for the API to do it. Google APIs historically have not always exposed every action that a user can do. You might be out of luck if you want to do it with the API.

https://developers.google.com/drive/api/v3/about-shareddrives

The API docs do not mention moving files into shared drives at all; only managing a shared drives's permissions.