同域下Apps Script通过OAuth2调用Urlfetch的权限问题
跨账号调用Google Apps Script Web App失败问题
场景说明
- 同一域名下有两个账号
- 每个账号都包含两个相同的Apps Script函数:
fetch和doGet doGet函数已部署为仅允许域内访问的Web App- 核心问题:仅能从同一用户账号调用
doGet函数
场景示意图

相关代码
doGet 函数代码
function doGet(e) { var output = ContentService.createTextOutput(JSON.stringify({"code": 200, "data": "aaaa"})).setMimeType(ContentService.MimeType.JSON); return output; } // 已部署为Web App,仅允许域内访问
fetch 函数代码
function fetch() { let options = { muteHttpExceptions: true, method: 'GET', headers: { Authorization: `Bearer ${ScriptApp.getOAuthToken()}` } }; // DEPLOYMENT_ID会根据调用的是用户1还是用户2的test_doGet而变化 var url = "https://script.google.com/a/macros/<DOMAIN>/s/<DEPLOYMENT_ID>/exec"; var r = UrlFetchApp.fetch(url, options); Logger.log(r.getContentText()); // 跨用户调用时返回错误 }
关键现象
注意:当登录用户1账号,在浏览器中手动访问用户2的
test_doGetURL时,能正常访问!
请问我哪里操作有误?
内容的提问来源于stack exchange,提问作者Waxim Corp
相关产品推荐
相关产品推荐

