0

I created a service account using the following: https://developers.google.com/drive/web/delegation I downloaded the file it asked me to download as a JSON file if that makes a difference.

Now how do I use that service account to initiate an ownership transfer using app script?

function transferOwnership() {
  var fileId = "1YzwfuawY8OiFIw-nbUCagTUhrxmqH2PEyMmYz1NMT9A";

  var p = {};
  p.role = "owner";
  p.type = "user";
  p.value = "email@ofnewowner.com";

  Drive.Permissions.insert(p,fileId);
}
Bjorn Behrendt
  • 1,204
  • 17
  • 35

1 Answers1

0

If the file is in Drive, you should try doing something like this:

 function transferOwnership() {
  var fileId = "1YzwfuawY8OiFIw-nbUCagTUhrxmqH2PEyMmYz1NMT9A";

  var owner = "email@ofnewowner.com";

  Drive.getFileById(fileId).setOwner(owner);
}

Hope this helps!

pointNclick
  • 1,584
  • 1
  • 12
  • 17
  • That only works if the owner is the one running the script. I am trying to use a sub-admin with service account to impersonate the owner and change the ownership for them. – Bjorn Behrendt Sep 24 '15 at 20:33