gpt4 book ai didi

javascript - 如何使用javascript通过api在我的谷歌应用程序脚本中运行一个函数

转载 作者:行者123 更新时间:2023-11-28 03:50:40 26 4
gpt4 key购买 nike

我想在我的谷歌应用程序脚本文件中运行一个函数。但是我怎样才能在外部网站上通过 api 运行它。请帮助任何人。

我试着像这样发送一个 api 请求目标脚本代码.gs

 function addtext(sheetId) {
var ss = SpreadsheetApp.openById(sheetId);
ss.appendRow(['test', 'blabla'])
});
}

和javascript这样 var scriptId = "";

 // Initialize parameters for function call.
var sheetId = "<ENTER_ID_OF_SPREADSHEET_TO_EXAMINE_HERE>";

// Create execution request.
var request = {
'function': 'addtext',
'parameters': [sheetId],
'devMode': true
};

// Make the request.
function apire() {
gapi.client.request({
'root': 'https://script.googleapis.com',
'path': 'v1/scripts/' + scriptId + ':run',
'method': 'POST',
'body': request
});
}

最佳答案

可以关注JavaScript Quickstart :

HTML Service: Communicate with Server Functions

google.script.run is an asynchronous client-side JavaScript API that allows HTML-service pages to call server-side Apps Script functions. The following example shows the most basic functionality of google.script.runcalling a function on the server from client-side JavaScript.

HTML

<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
google.script.run.doSomething();
</script>
</head>
</html>

code.gs

function doGet() {
return HtmlService.createHtmlOutputFromFile('Index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function doSomething() {
Logger.log('I was called!');
}

For an in-depth example, complete the steps described in the rest of this page, and in about five minutes you'll have a simple JavaScript application that makes requests to the Google Apps Script Execution API.

关于javascript - 如何使用javascript通过api在我的谷歌应用程序脚本中运行一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37740588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com