我想测试是否可以使用Google电子表格中的UrlFetchApp.fetch
发送请求。这是我的代码:
function createSpreadsheetOpenTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('myOnEdit')
.forSpreadsheet(ss)
.onEdit()
.create();
}
function myOnEdit(){
var response = UrlFetchApp.fetch('http://www.google.com/');
Logger.log(response.getContentText());
}
当我测试功能createSpreadsheetOpenTrigger
时,它会显示一个提示框authorization required
,当我点击审核权限按钮并登录时会显示This app isn't verified
。我也不确定如何使用可安装的触发器,以便我的自定义onEdit工作。
我很感激任何有用的例子,因为我已经花了很长时间才开始工作。感谢。
答案 0 :(得分:0)
有两种类型的脚本:
绑定脚本可以调用一些独立脚本不能的方法:
您还可以手动在绑定脚本中创建可安装的触发器: The official documentation:
要通过脚本编辑器中的对话框手动创建可安装触发器,请执行以下步骤:
以编程方式制作可安装的触发器:
https://developers.google.com/apps-script/reference/script/trigger-builder#forSpreadsheet(String)
ScriptApp.newTrigger('myFunction')
.forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz')
.onEdit()
.create();
摘要:要从独立脚本创建此触发器,只需通过调用SpreadsheetApp.getActive()
替换SpreadsheetApp.openById(id)
即可。 ID是电子表格的关键:例如,网址https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0中的电子表格ID为“abc1234567”。
代码:
function createSpreadsheetOpenTrigger() {
ScriptApp.newTrigger('myOnEdit')
.forSpreadsheet('ID')
.onEdit()
.create();
}
function myOnEdit(){
var response = UrlFetchApp.fetch('http://www.google.com/');
Logger.log(response.getContentText());
}