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应用程序脚本中运行我的功能 已经在google上搜索,结果必须使用google.script.run。当我尝试它时,我发现google不起作用 这是我的.gs应用程序脚本中的代码: /** * This script demonstrates the use of objDB using a spreadsheet as a database * * objDB is a Google Script Library that makes it

我真的需要帮助从我的网站/本地主机在google应用程序脚本中运行我的功能

已经在google上搜索,结果必须使用
google.script.run
。当我尝试它时,我发现
google
不起作用

这是我的
.gs
应用程序脚本中的代码:

/**
*  This script demonstrates the use of objDB using a spreadsheet as a database
*
*  objDB is a Google Script Library that makes it easy to work with data stored in a spreadsheet.
*  Using the same functions, you can also work with data from a JDBC-connected database.
*  See http://googlescripts.harryonline.net/objdb for full documentation
*  
*  This demo uses the spreadsheet template from the tutorial on the Google Apps Script
*  https://developers.google.com/apps-script/storing_data_spreadsheets#reading
*  
*/

/**
*  To restore the data from the original spreadsheet, run getSpreadsheet()
*  Try out the sample function, and create your own.
*  See the results in the log, as well as on the spreadheet itself
*  You can view the log file using View - Logs, or Alt-Enter
*  Alternatively, put breakpoints at the Logger.log statements and use Debug instead of Run

/**
*  Create a copy of the tutorial spreadsheet and stores the ID of the newly created spreadsheet
*  in Usersettings, so you can continue using this.
*  Restore data from original tutorial spreadsheet
*/

function getSpreadsheet()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Tutorial Data');
  sheet.clear();
  var tutorialID = '0Aq4s9w_HxMs7dFNtWlh2MHRWZzEtbk5LRW5hTVR1Y1E';
  var tutorialDataRange = SpreadsheetApp.openById(tutorialID).getSheets()[0].getDataRange();
  var range = sheet.getRange(1,1,tutorialDataRange.getNumRows(), tutorialDataRange.getNumColumns());
  range.setValues(tutorialDataRange.getValues());
}

/**
*  Sample: get all data from Engineering employees
*/

function getEngineers()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ssDB = objDB.open( ss.getId());
  var rows = objDB.getRows(ssDB, 'Tutorial Data', [], {Department:'Engineering'});
  Logger.log( rows );
}

/**
*  Sample: get John's phone number
*  Note that non-alphanumeric characters are stripped from column names: Phone Number becomes PhoneNumber
*/

function getPhone()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ssDB = objDB.open( ss.getId());
  var rows = objDB.getRows(ssDB, 'Tutorial Data', ['PhoneNumber'], {FirstName:'John'});
  Logger.log( rows );
}

/**
*  Delete staff with id's 1342 and 1234 
*/

function deleteStaff()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ssDB = objDB.open( ss.getId());
  var rowCount = objDB.deleteRow(ssDB, 'Tutorial Data', {EmployeeId:[1342,1234]});
  Logger.log( rowCount );
}

/**
*  Update: staff 3512 goes to marketing
*/

function updateStaff()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ssDB = objDB.open( ss.getId());
  var rowCount = objDB.updateRow(ssDB, 'Tutorial Data', {Department:'Marketing'}, {EmployeeId:3512});
  Logger.log( rowCount );
}

/**
*  Add new employee
*/

function addStaff()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  ssDB = objDB.open( ss.getId());
  var rowCount = objDB.insertRow(ssDB, 'Tutorial Data', {FirstName:'Harry', LastName:'Potter', EmployeeId:4321, Department:'Magic',PhoneNumber:'(212) 123-4567'});
  Logger.log( rowCount );
}

我仔细阅读了谷歌的应用程序脚本。应用程序脚本基本上是为开发人员提供扩展谷歌应用程序(电子表格、日历、gmail、文档等)的服务而构建的,从设计上看,这些应用程序应该位于谷歌云服务器上并从中运行

因此,您不能在您的网站/本地主机上运行它们,因为GS脚本是在服务器端(google服务器)执行的。


唯一建议的方法是。我认为这不是你的情况。

我仔细阅读了谷歌的应用程序脚本。应用程序脚本基本上是为开发人员提供扩展谷歌应用程序(电子表格、日历、gmail、文档等)的服务而构建的,从设计上看,这些应用程序应该位于谷歌云服务器上并从中运行

因此,您不能在您的网站/本地主机上运行它们,因为GS脚本是在服务器端(google服务器)执行的。


唯一建议的方法是。我认为这不是你的情况。

要从外部网页或服务运行谷歌应用程序脚本,你可以使用。此链接包括多种语言的示例,包括但不限于JavaScript、PHP和Python。

要从外部网页或服务运行Google应用程序脚本,您可以使用。此链接包括多种语言的几个示例,包括但不限于JavaScript、PHP和Python。

可能是您能做的最好、最简单的事情

使用本地隧道 通过这种方式,可以从任何计算机或Google服务器访问您的本地主机

Localtunnel允许您在本地开发机器上轻松共享web服务,而无需干扰DNS和防火墙设置


将baseURL更改为本地隧道提供的URL,它将像一个符咒一样工作。

这可能是您能做的最好、最简单的事情

使用本地隧道 通过这种方式,可以从任何计算机或Google服务器访问您的本地主机

Localtunnel允许您在本地开发机器上轻松共享web服务,而无需干扰DNS和防火墙设置


将baseURL更改为本地隧道提供的URL,它将非常有用。

您的页面中不应该包含任何其他.js文件吗?@BehradKhodayar我的网页中必须包含哪些javascript文件?通常您应该在文档中包含第三方库,以便能够使用它,但没有第三方库库如果要从非Google产品运行应用程序脚本代码,可以向应用程序脚本项目中的
doGet()
doPost()
函数发出HTTPS GET或POST请求
doGet()
doPost()
是保留函数名,由对应用程序脚本Web App的已发布URL的GET或POST请求触发。返回值可以从应用程序脚本发送回使用Content Service发出GET或POST请求的任何人。请参阅以下文章:您的页面中不应该包含任何其他.js文件吗?@BehradKhodayar我必须在我的网页中包含哪些javascript文件?通常,您应该在文档中包含第三方库才能使用它,但如果您想从非谷歌网站运行应用程序脚本代码,则没有第三方库产品,您可以向应用程序脚本项目中的
doGet()
doPost()
函数发出HTTPS GET或POST请求
doGet()
doPost()
是保留函数名,由对应用程序脚本Web App的已发布URL的GET或POST请求触发。返回值可以从应用程序脚本发送回使用Content Service发出GET或POST请求的任何人。请参阅下面的Stack Overfow post:还有另一种方法。请参阅@Rubén,谢谢,但这里的案例并不是针对API版本的(正如我在回答末尾所建议的)。他试图将.gs文件上传到他的主机/本地主机&。这就是为什么我对错误的流程提出了警告。不客气。看起来我对这个问题的理解和你不一样。另一方面,你的建议和我的不一样:)还有另一种方法。请参阅@Rubén,谢谢,但这里的案例并不是针对API版本的(正如我在回答末尾所建议的)。他试图将.gs文件上传到他的主机/本地主机&。这就是为什么我对错误的流程提出了警告。不客气。看起来我对这个问题的理解和你不一样。另一方面,你的建议和我的不一样:)