0

Google API Admin SDK Data Transfer: Can be found here

I have been able to successfully copy over all files from 1 Google account to another, but I am looking to copy over just 1 specific file. Scopes and permissions are correct.

The successful API request body to move all files is:

{
  "oldOwnerUserId": "{ID transferring from}",
  "newOwnerUserId": "{ID Transferring to}",
  "applicationDataTransfers": [    
    {
      "applicationId": "{Google Drive Application ID}"
    }
  ]
}

The ID for the Google Drive Folder I'm looking to copy over is 1HCrNywrvoUly_MrYndR. How can I adapt this code to only transfer over this Google Drive folder?

Alternatively, is there a way I can create default folders in other user's accounts through the Google API? I need to create a set of blank folders for every new user that creates an account and haven't been able to find a way to create folders in other accounts using the Google Drive API. This workaround is to create all folders in my Google Drive and then using the Admin SDK API to ship off the completed folder to the new user.

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
Duke
  • 163
  • 8
  • Are you trying to copy over a specific folder, or a Drive? The ID you've posted has the form of a Drive and not a file/folder. – Rafa Guillermo Jan 22 '20 at 10:00
  • I’m trying to copy a specific Google Drive folder (I didn’t put the actual folder ID) – Duke Jan 22 '20 at 12:56

2 Answers2

0

Answer:

The Admin SDK API does not have methods which allow you to copy a single file or folder from one user account's Drive to another. For this, you must use the Google Drive API.

More Information:

You will need to use a service account to do this, as to authorise an application as more than one user you must have an application being run with an account that has domain-wide delegation, but once this has been set up in your Google Cloud Project Console, you can use the regular Google Drive API methods to copy individual files or folders from one Drive to another.

Things to be aware of:

  • You will need to use the delete and add methods of the Drive API to create the files/folders, rather than copying them.
  • If there are files inside a folder you wish to copy over, you will need to copy these recursively into the newly created folder.
  • You can get a list of the files in a folder using the list method of Drive: files in the API.

References:

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
0

After digging around, I found a solution that was way less complicated than using a Google Service Account. All you need is Admin credentials.

if you create a folder in your own Google Drive through the API, you can load it up with whatever you want. After that, you can then change the permissions of the parent folder to make the target user an owner. You then delete your own permissions and voila, that file now belongs to the other person.

Duke
  • 163
  • 8