简体   繁体   中英

Transfer Ownership of Google Sheets from Service Account to General Account

I created a Google sheet using Google Sheets API which copied the content of spreadsheet present in one of my folder in Google Drive. Even the copied file did contain the code of App Script in it. So the file which was created using service account didn't allowed me to use the code of App Script. It throws the following error as shown in image below: 运行函数时出错

When I created the copy of this file from front end as shown in image below: 电子表格文件的副本 In this case owner was not service account so I was able to use the App Script.

Can any one help me with this?

You can programmatically make a Permissions.List using the service account credentials to make another user the owner of the file (the Spreadsheet in this case, you need its ID), you need to set the transferOwnership attribute to true and use a request body like this:

{
  "role": "owner",
  "type": "user",
  "emailAddress": "new-owner@email.com"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM