尝试执行Google Apps脚本时值不正确 [英] Bad value when trying to execute google Apps Script

查看:55
本文介绍了尝试执行Google Apps脚本时值不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行一个简单的Apps脚本以从我的Google工作表中检索数据.但是,我得到了错误:

I am trying to execute a simple Apps script to retrieve data from my google sheet. However, I get the error:

错误值(第2行,文件代码",项目无标题的项目")

Bad value (line 2, file "Code", project "Untitled project")

当我粘贴链接时: https://script.google.com/macros/s/AKfycbw8_1qGhuEMvfOEbLAx69x4fXyPl4sKQc4dvka81i5t42MkZpU/exec (发布后为我的网络应用提供的链接)进入我的浏览器,然后按Enter.

when I paste the link:https://script.google.com/macros/s/AKfycbw8_1qGhuEMvfOEbLAx69x4fXyPl4sKQc4dvka81i5t42MkZpU/exec (the link provided for my web app after publishing) into my browser and hit enter.

但是,当我在发布后单击测试Web应用程序的最新代码"时,它将正确显示JSON,没有任何问题.我的应用脚本代码如下:

However,when I click "test web app for your latest code" after publishing, it displays the JSON correctly without any issues. My app script code is as follows:

function doGet() {
  var ss = SpreadsheetApp.openById('1gQKvGO0fhcrgqeke8HkUqm5Mb9dXWbaflIDmIo-pWcA');
  var sheet = ss.getSheets()[0];

  // Get the range of cells that store employee data.
  var employeeDataRange = ss.getRangeByName("Range1");

  // For every row of employee data, generate an employee object.
  var employeeObjects = getRowsData(sheet, employeeDataRange);
  return ContentService.createTextOutput(JSON.stringify(employeeObjects)).setMimeType(ContentService.MimeType.JSON);
}

其他帖子提到电子表格ID必须正确,但是我很确定我的ID是正确的.

Other posts mention that the spreadsheet id must be correct but I am pretty sure my id is correct.

推荐答案

从您的问题来看,您似乎已经更改了代码,但尚未使用最新版本重新发布它,因此当您测试Web应用程序以获取最新代码时" ",它可以正常工作,但是当您使用发布链接时,它就会崩溃.

From your question, it seems that you have changed the code but you have not republished it with latest version, so when you "test web app for your latest code", it works fine but when you use your publishing link, it crashes.

转到:发布>作为Web应用程序部署>选择项目版本新建并更新项目.

go to : publish > deploy as webapp > select project version to new and update the project.

这篇关于尝试执行Google Apps脚本时值不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆