0

I am trying to do transfering of file ownership to an emailaddress. I send this first request,

var body = {
    'emailAddress': value,
    'type': type,
    'role': "writer"
  };
  var request = gapi.client.drive.permissions.create({
    'fileId': fileId,
    'transferOwnership': false,
    'resource': body
  });
  request.execute(function(resp) { 
      ...
  });

This will create a permission writer for that emailaddress. After that, inside the request.execute() callback, I send the second request,

var request2 = gapi.client.drive.permissions.list({
      'fileId': fileId
    });
    body.role = role;
    request2.execute(function(resp2) { 
      var request3 = gapi.client.drive.permissions.update({
        'fileId': fileId,
        'permissionId': resp2.permissions[1].id, //permission id of writer
        'transferOwnership': true,
        'resource': {'role':role, 'emailAddress': value}
      });
      request3.execute(function(resp3) {
        console.log(resp3);
      });
    });

In the above request, I used permissions.list to get the file permission id. Then I used the permission id to update permissions. I used permissions.update request for transferOwnership. The problem I encountered here is "The user does not have sufficient permissions for this file."

What I am trying to do here is transfer the file ownership to an emailaddress. What is wrong with my codes? How can I transfer file ownership?

JMA
  • 974
  • 3
  • 13
  • 41

1 Answers1

1

You need to think about the old and new owners of the file. Unless they are in the same Google Accounts domain, (eg. foo@example.com as opposed to foo@gmail.com) you can't transfer ownership. Although it might sound inconvenient, there would be a clear security problem if this were to be allowed.

If they are in the same domain, confirm that you have a scope with sufficient privilege.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • Can you provide a sample transferring ownership of the file using the domain? – JMA Mar 14 '17 at 16:25
  • look at https://github.com/pinoyyid/googleDriveTransferOwnership/blob/master/src/couk/cleverthinking/tof/Main.java – pinoyyid Mar 14 '17 at 23:23
  • the old owner is a service account (gserviceaccount.com, not a real e-mail); the new owner is a gmail.com account. Are you saying there is no way to set myself as the owner of a file i created with my own service account? – Michael Apr 03 '22 at 17:58
  • @Michael I am trying to get the same thing done. Were you able to resolve this? – PRANSHU MIDHA Nov 21 '22 at 13:15