查询错误:从电子表格创建图表时 JSON 字符串无效?气体

Error in query: Invalid JSON string when Creating a Chart from a Spreadsheet? GAS

为什么我在尝试使用文档 here 中的 Google 示例脚本从电子表格创建图表时收到错误查询错误:无效的 JSON 字符串?

我想不通。我唯一更改的是电子表格 URL。其余部分直接来自文档示例。我在下面提供了我的所有代码。你们能提供的任何帮助将不胜感激。 谢谢, 布兰登

function doGet() {
  return HtmlService.createTemplateFromFile('index')
    .evaluate()
    .setSandboxMode(HtmlService.SandboxMode.NATIVE);
};

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
};

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">

      // Load the Visualization API and the controls package.
     google.load("visualization", '1', {packages:['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
  var query = new google.visualization.Query(
      'https://docs.google.com/a/sleschool.org/spreadsheets/d/1TRcHxsLuunRUPgn-i-h3OcVvh0TNp_VhJrNBI3ulMlA/edit#gid=0');
  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }

  var data = response.getDataTable();
  var chart = new google.visualization.ColumnChart(document.getElementById('columnchart'));
  chart.draw(data, { legend: { position: 'none' } });
}
</script>

<title>Data from a Spreadsheet</title>
</head>

<body>
<span id='columnchart'></span>
</body>
</html>

<div id="EntireSite">

  <div>
    <?!= include('Chart'); ?>
  </div>
  

HtmlService.SandboxMode.NATIVE 行将其更改为 HtmlService.SandboxMode.IFRAME 这样我就可以 运行 您添加的文档代码。