I have a google drive folder shared with three users
- me@myorg.com
- main@myorg.com
- service account
What I want to accomplish is any files that I upload (using the me account) has their ownership transferred to the main account.
The google admin console provides a way to transfer all files from one user in the organization to another user, but I don't want to transfer all files; I only want to transfer specific files.
Using google drive API v3, after authenticating using the service account, I am able to successfully list the files and see the file as well as the permissions of each user that it's shared with
FileList result = service.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name, permissions)")
.execute();
List<File> files = result.getFiles();
for (File file : files) {
for (Permission perm : file.getPermissions()) {
if (perm.getEmailAddress().equals("main@myorg.com")) {
Permission permObj = service.permissions().get(file.getId(), perm.getId()).setFields("role").execute();
permObj.setRole("owner");
service.permissions().update(file.getId(), perm.getId(), permObj).setFields("role").setTransferOwnership(true).execute();
}
}
}
When I do this, I get an error message
The user does not have sufficient permissions for this file.
I guess the problem here is the service account isn't actually the owner of the file, and therefore isn't able to transfer ownership?
Or perhaps the service account isn't part of the organization (it doesn't have a myorg.com domain)?
Would I need to enable domain-wide delegation for the service account to impersonate the owner, in order to transfer ownership on behalf of the owner (ie: me to main)?
What are some other options to transferring file ownership that doesn't require explicit user authorization?