我正在研究一种方法,通过 oAuth 规范和 AWS API 网关调用来限制特定用户的某些 Google 表格,但我遇到了一个问题ScriptApp.getOAuthToken()
功能。
当我使用 Google Apps 脚本调试器运行代码时,一切都很好,ScriptApp.getOAuthToken()
返回一个可以传递给我的 AWS API 的令牌。目前的预期结果只是接收用户名。
但是,如果我尝试在 Google 表格单元格中使用我的函数作为宏,则会出现以下错误Header:null (line 13)
这是 Code.gs 文件中的代码
function HelloW() {
var token = ScriptApp.getOAuthToken();
var headers = {
'Authorization' : token
}
var options = {
'headers' : headers,
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch('https://###/demo-lambda', options);
var txt = response.getContentText();
var json = JSON.parse(txt);
var name = json.Message;
return name;
}
和清单以防万一
{
"timeZone": "Europe/Paris",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/drive"],
"sheets": {
"macros": [{
"menuName": "HelloW",
"functionName": "HelloW"
}]
}
}
我有一个错误,因为token
为空,但我不明白为什么它在调试器中运行良好,但在表格文档中却不然。我错过了一些东西,但我找不到什么。
任何帮助将非常感激。