【问题标题】:Is there any debugger for Google Ads-scripts?谷歌广告脚本有调试器吗?
【发布时间】:2021-02-01 02:19:43
【问题描述】:

我编写了我的第一个 *.gs Google Ads 脚本文件。

是否有可以添加断点或查看变量状态的 IDE 或环境?

我只看到logger 打印,但使用起来效率不高。

我尝试了@Andrew 的回复,但没有成功:

【问题讨论】:

    标签: google-sheets-api google-ads-api google-ads-script


    【解决方案1】:

    您可以在行号旁边放置点,然后点击小虫子图标,如图所示。

    这将打开这个调试屏幕:

    【讨论】:

    • 我的意思是 google-ads-script 不是 google-apps-script。修复了标签。你从哪里运行这个?
    • 啊,从未使用过 Google Ads 脚本,但这可能仍然有效,因为它们也是 .gs 文件。我总是通过打开 Google 电子表格并转到 Extra > Script Editor 来运行它。但您可以通过 script.google.com 轻松访问它。
    • 另外记得点击调试图标,而不是运行图标(看起来像bug的按钮,不是播放按钮)
    【解决方案2】:

    你可以使用这个功能。

    例如: MyLogger("test");

    function MyLogger(s,d=true,w=800,h=400,t=5) {
      const cs=CacheService.getScriptCache();
      const cached=cs.get("Logger");
      const ts=Utilities.formatDate(new Date(), SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "MM|dd|HH:mm:ss")
      if(cached) {
        var v=Utilities.formatString('%s<br />[%s] - %s',cached,ts,s);   
      }else{
        var v=Utilities.formatString('[%s] - %s',ts,s);
      }
      cs.put("Logger",v,t);
      //allows logging without displaying.
      if(d) {
        const a='<br /><input type="button" value="Exit" onClick="google.script.host.close();" />';
        const b='<br /><input type="button" value="Exit" onClick="google.script.host.close();" /><br />';
        SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(b+v+a).setWidth(w).setHeight(h), 'My Logger');
      }
    }
    

    (要查看日志,请使用您的脚本打开电子表格)

    【讨论】:

    • 不确定缺少什么:添加了您的方法(请参阅原始帖子文本)。
    • Cannot call SpreadsheetApp.getUi() from this context.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    相关资源
    最近更新 更多