How to transfer File Ownership for a Document whic

2019-05-17 19:30发布

问题:

Use Case

  • As admin service account, transfer Document Ownership using the Google Docs API, similar to the built in cPanel "Advanced Tools" -> "Document ownership transfer"

Constraints

  • APIs are being invoked in context of a Google Apps admin service account rather than the end-user account since APIs are being invoked from Google Apps Script in Sites page

  • Authorization is OAuth 1.0 since this is what Apps Script supports

What works:

  • Transferring ownership of the admin service account's own files to another user's account as documented here

What is required:

  • Transfer ownership of another user's files, ideally without them sharing any permissions with the admin service account; if there's no other way of doing it, they could share edit permissions on the file with the admin service account.
  • Currently this returns a

    " ServiceException - You do not have permission to share these item(s):"

回答1:

What you're trying to do is possible by impersonating the user using the admin account. The documentation shows how to do this here.

Essentially, start by requesting the API URL with default replaced with the current owner's email address. The request must be made while authorized as the admin user, though.

https://docs.google.com/feeds/user@yourdomain.com/private/full/

Once that URL is requested, all feed URLs will be returned with that email already present. Then, simply change ownership as you would normally.