Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么每次我保存时,谷歌应用程序脚本都会将我的用户属性更改为一些随机代码?_Javascript_Google Apps Script - Fatal编程技术网

Javascript 为什么每次我保存时,谷歌应用程序脚本都会将我的用户属性更改为一些随机代码?

Javascript 为什么每次我保存时,谷歌应用程序脚本都会将我的用户属性更改为一些随机代码?,javascript,google-apps-script,Javascript,Google Apps Script,我正在为google sheets创建一个编辑器加载项,目前我很困惑,为什么每次我尝试使用setProperty将我的用户属性(my_WEBHOOK)保存到以下代码时都会更改它: function(){var L=h(fb(参数));if(b&32)Vd(function(){a.apply(g | | this,L)};else返回m(a.apply(g | | this,L))} 以下是我正在使用的代码: code.gs: 函数保存设置(url){ PropertiesService.ge

我正在为google sheets创建一个编辑器加载项,目前我很困惑,为什么每次我尝试使用
setProperty
将我的用户属性(
my_WEBHOOK
)保存到以下代码时都会更改它:

function(){var L=h(fb(参数));if(b&32)Vd(function(){a.apply(g | | this,L)};else返回m(a.apply(g | | this,L))}
以下是我正在使用的代码:

code.gs

函数保存设置(url){
PropertiesService.getUserProperties().setProperty('MY_WEBHOOK',url);
SpreadsheetApp.getUi().alert(“已保存”)
}
函数getSettings(){
返回PropertiesService.getUserProperties().getProperty('MY_WEBHOOK');
}
在我的html文件中:


什么是URL?


函数save(){ var url=document.getElementById('webhook-url')。值 google.script.run.saveSettings(url) 警报(url) 警报(google.script.run.getSettings) google.script.host.close() } 函数get(){ var settings=google.script.run.getSettings document.getElementById('webhook-url')。值=设置; }
修改点: 我认为您的脚本中有两个修改点

  • 关于
    google.script.run.getSettings
    ,在本例中,
    getSettings
    的功能不运行。请添加
    ()
    google.script.run.getSettings()
    。这样,函数就运行了。
    • 我想这就是你的问题所在
  • 关于
    alert(google.script.run.getSettings)
    var settings=google.script.run.getSettings
    google.script.run
    不返回任何值。因此,在本例中,使用了带有SuccessHandler的
  • google.script.run
    与异步进程一起运行
  • 当上述各点反映到脚本中时,它将变成如下所示

    function save() {
      var url = document.getElementById('webhook-url').value
      google.script.run.withSuccessHandler(() => {
        google.script.run.withSuccessHandler(e => {
          alert(e);
          google.script.host.close();
        }).getSettings();
      }).saveSettings(url);
    }
    
    function get() {
      google.script.run.withSuccessHandler(settings => {
        document.getElementById('webhook-url').value = settings;
      }).getSettings();
    }
    
    修改脚本: 请按如下方式修改您的Javascript

    function save() {
      var url = document.getElementById('webhook-url').value
      google.script.run.withSuccessHandler(() => {
        google.script.run.withSuccessHandler(e => {
          alert(e);
          google.script.host.close();
        }).getSettings();
      }).saveSettings(url);
    }
    
    function get() {
      google.script.run.withSuccessHandler(settings => {
        document.getElementById('webhook-url').value = settings;
      }).getSettings();
    }
    
    • 使用上述脚本时,首先通过
      get()
      getSettings
      检索值,当输入值并单击按钮时,通过
      saveSettings()
      输入值,通过
      getSettings()
      检索当前值,并运行
      alert()
      ,然后,运行
      google.script.host.close()
    注:
    • 这是一个简单的修改。因此,请根据您的实际情况进行修改
    参考:
    修改点: 我认为您的脚本中有两个修改点

  • 关于
    google.script.run.getSettings
    ,在本例中,
    getSettings
    的功能不运行。请添加
    ()
    google.script.run.getSettings()
    。这样,函数就运行了。
    • 我想这就是你的问题所在
  • 关于
    alert(google.script.run.getSettings)
    var settings=google.script.run.getSettings
    google.script.run
    不返回任何值。因此,在本例中,使用了带有SuccessHandler的
  • google.script.run
    与异步进程一起运行
  • 当上述各点反映到脚本中时,它将变成如下所示

    function save() {
      var url = document.getElementById('webhook-url').value
      google.script.run.withSuccessHandler(() => {
        google.script.run.withSuccessHandler(e => {
          alert(e);
          google.script.host.close();
        }).getSettings();
      }).saveSettings(url);
    }
    
    function get() {
      google.script.run.withSuccessHandler(settings => {
        document.getElementById('webhook-url').value = settings;
      }).getSettings();
    }
    
    修改脚本: 请按如下方式修改您的Javascript

    function save() {
      var url = document.getElementById('webhook-url').value
      google.script.run.withSuccessHandler(() => {
        google.script.run.withSuccessHandler(e => {
          alert(e);
          google.script.host.close();
        }).getSettings();
      }).saveSettings(url);
    }
    
    function get() {
      google.script.run.withSuccessHandler(settings => {
        document.getElementById('webhook-url').value = settings;
      }).getSettings();
    }
    
    • 使用上述脚本时,首先通过
      get()
      getSettings
      检索值,当输入值并单击按钮时,通过
      saveSettings()
      输入值,通过
      getSettings()
      检索当前值,并运行
      alert()
      ,然后,运行
      google.script.host.close()
    注:
    • 这是一个简单的修改。因此,请根据您的实际情况进行修改
    参考:

    答案不错,但我认为您的代码有一个错误:第一个
    with SuccessHandler
    (属于
    saveSettings
    )缺少函数声明(常规或箭头声明)@Martí感谢您的评论。你说得对。那是因为我的复制粘贴错误。在本例中,在当前脚本中,首先运行内部
    google.script.run
    。起初,我想提出像
    google.script.run.withSuccessHandler(google.script.run.withSuccessHandler(e=>{alert(e);google.script.host.close();}).getSettings)这样的建议。但从你的评论来看,我认为这也是低可读性。根据您的评论,我可以使用arrow函数修改脚本。感谢您的支持。回答很好,但我认为您的代码有一个错误:
    withSuccessHandler
    (属于
    saveSettings
    )的第一个
    缺少函数声明(常规声明或箭头声明)@Martí感谢您的评论。你说得对。那是因为我的复制粘贴错误。在本例中,在当前脚本中,首先运行内部
    google.script.run
    。起初,我想提出像
    google.script.run.withSuccessHandler(google.script.run.withSuccessHandler(e=>{alert(e);google.script.host.close();}).getSettings)这样的建议。但从你的评论来看,我认为这也是低可读性。根据您的评论,我可以使用arrow函数修改脚本。谢谢你的支持。