0

my scenario: I have created a folder inside my Google Drive with the name called folder-root and shared that folder with my colleagues. My company is using G-Suite for business. Now my other team members have started uploading files and folder inside my folder. Now I want to take ownership of all files and folder created/uploaded inside my folder to me.

e.g. the hierarchy is

  • folder-root --I am the owner
    • folder-1 -- Bob is the owner
      • file-1 -- Bob is the owner
    • folder-2 -- Alice is the owner
      • file-2 -- Alice is the owner
    • file-3 -- marry is the owner

Since all the files and folders are created inside my Drive folder so I want to take ownership of all files/folders created inside my folder.

How can do that , I have tried using Google API's v3, and I am getting an error: Bad Request. User message: "Sorry, you do not have permission to share."

this message is coming when I use file id of bob, Alice or marry with my email address

Code is in node.js

function transferOwnerShip(auth) {
    const drive = google.drive({version: 'v3', auth});
    drive.permissions.create({
        fileId: '1_o-rhbFinu1_LZYniFNo1gV0Epv5mYU5',
        transferOwnership: 'true',
        resource: {
          role: 'owner',
          type: 'user',
          emailAddress: 'my-name@company.com'
        }
      });
  }
Rubén
  • 34,714
  • 9
  • 70
  • 166
Mahajan344
  • 2,492
  • 6
  • 39
  • 90
  • 1
    Just a guess is that you can't transfer ownership unless you are currently the owner. You could copy the files, or get the current owners to transfer to you. Or maybe your G Suite admin could assist you. – dwmorrin Aug 16 '20 at 12:22
  • 1
    This repo probably does more or less what you are looking for https://github.com/pinoyyid/googleDriveTransferOwnership – pinoyyid Aug 17 '20 at 09:09
  • @pinoyyid Thank you very much for such a great utility! That's exactly what I was looking for too long. – Yevgen Apr 21 '21 at 19:13

1 Answers1

2

To transfer the ownership of file (including Google Drive folders which in the REST Google Drive API are referred as files) the code should be executed with the permissions of the file owner. This could be done using OAuth instead of using Node.js (or other platform / programming language use Google Apps Script which handles the OAuth for your with some restrictions.

If you can't get that the file owners do the ownership transfer you will need a Google Service Account with domain-wide delegation of authority to impersonate them. This requires that a G Suite admin gives this privilege to the service account.

Another option is that the G Suite admin transfer the ownership of all the files of those user to another user. If you aren't that user, they should transfer the ownership of the files to you.

You could validate the above directly with G Suite Support if you are a G Suite admin.

Another option is to copy the files that you don't own, then remove the files owned by others from your folders. In order to prevent that this happens again, change from edit to view on the sharing settings of your folders. This could be done manually or by using the Google Drive API.

Resources

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166