我在尝试同时使用 DriveApp 和 GmailApp 时遇到了 Google Apps 脚本问题。情况是这样的:
代码.gs
function test () {
let folder = DriveApp.getFolderById(FolderID);
let threads = GmailApp.search('is:starred')
let sheet = SpreadsheetApp.openById(sheetID)
console.log({
folder : folder,
threads : threads,
sheet : sheet
})
}
当这两个服务在同一个脚本中一起调用时,会抛出错误。
错误:“异常:需要授权才能执行该操作测试@code.gs.2”
我尝试过的故障排除步骤:
对我来说运行良好:
function test () {
let folder = DriveApp.getFolderById(gobj.globals.testfolderid);
let threads = GmailApp.search('is:starred')
let sheet = SpreadsheetApp.openById(gobj.globals.test1id)
Logger.log(JSON.stringify({
folder : folder.getName(),
threads : threads,
sheet : sheet.getName()
}))
}
Execution log
9:42:35 AM Notice Execution started
9:42:35 AM Info {"folder":"Testfolder","threads":[{},{},{},{},{}],"sheet":"Test1"}
9:42:37 AM Notice Execution completed