我正在尝试使用clasp在本地构建GAS项目
https://github.com/google/clasp
任何本地安装的IDE都是对Google脚本编辑器的巨大改进,因此该工具看起来非常有前景.遗憾的是,GAS服务的自动完成功能似乎不包含在软件包中.
文件说:
Apps Script CLI使用TypeScript在开发时提供自动完成和linting.使用类似Visual Studio Code的IDE进行TypeScript自动完成.
完成所有必需的依赖项后,我仍然无法使用自动完成功能.当我为现有项目执行"clasp pull"命令时,它将".gs"扩展名转换为".js".自动填充建议只是解析现有代码的结果.
例如,如果我在我的代码中的某处调用了sheet.getRange(),那么'getRange()'方法会在建议中弹出,但我不能列出可用的选项,比如,PropertiesService,除非它已经在我的码.
有没有人为Google Apps脚本启用自动填充功能有什么好运?
我创建了 2 个简单的独立脚本来测试授权工作流程。第一个脚本是一个只有我可以访问的网络应用程序。
function doGet(e) {
return ContentService.createTextOutput(JSON.stringify({"message":"works!"}))
.setMimeType(ContentService.MimeType.JSON);
}
Run Code Online (Sandbox Code Playgroud)
调用脚本通过 ScriptApp.getAuthToken() 获取令牌并向 Web 应用程序发出“GET”请求。
function call() {
var token = ScriptApp.getOAuthToken();
var header = {"Authorization":"Bearer " + token};
var options = {
"method":"GET",
"headers": header,
"muteHttpExceptions": true
};
var url = 'APP_URL';
var response =UrlFetchApp.fetch(url, options);
Logger.log(response.getResponseCode()); //returns 401
Logger.log(response.getContentText()); // returns 'Unauthorized'
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它似乎不起作用,因为我收到了“未经授权”的回复。我最初的想法是令牌的范围是每个单独的脚本,但 GAS 文档表明相反,指出 ScriptApp 令牌在月情况下就足够了。
https://developers.google.com/apps-script/reference/script/script-app#getOAuthToken()
我将不胜感激任何帮助。