我正在创建一个用于 Google 电子表格的 Google Apps 脚本插件,但它需要能够访问单独的 Google 文档的内容,我正在使用DocumentApp.openById()执行此操作。我已经给脚本提供了这些范围:
"oauthScopes": [
"https://www.googleapis.com/auth/documents.readonly",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/spreadsheets.currentonly"
]
Run Code Online (Sandbox Code Playgroud)
但显然,这还不够。该脚本告诉我它需要https://www.googleapis.com/auth/documents许可才能正常工作。然而,当它只需要能够查看一个文件的内容时,授予该附加组件编辑所有 Google 文档文件的权限似乎有些过分。我错过了什么吗?有没有办法赋予它对单独的 Google 文档文件的只读访问权限?
这是我用于测试的函数,大部分文档 ID 已被删除:
function getDoc() {
var id = '1NLH----------------------------------------'
var templateFile = DocumentApp.openById(id)
var templateText = templateFile.getBody().getText()
Logger.log(templateText)
}
Run Code Online (Sandbox Code Playgroud)
谢谢!