Curl 如何知道Google应用程序脚本的进度状态
我创建了一个应用程序脚本,可自动执行多个任务:Curl 如何知道Google应用程序脚本的进度状态,curl,google-apps-script,httprequest,google-apps-script-api,Curl,Google Apps Script,Httprequest,Google Apps Script Api,我创建了一个应用程序脚本,可自动执行多个任务: Function 1. - Create a new folder and retrieve the ID. Function 2. - Create a copy of a doc file in the folder. Function 3. - Replace the text of several tags of type {{TEXT}} in the document. Function 4. - Insert an image in
Function 1. - Create a new folder and retrieve the ID.
Function 2. - Create a copy of a doc file in the folder.
Function 3. - Replace the text of several tags of type {{TEXT}} in the document.
Function 4. - Insert an image in the document.
Function 5. - Retrieve the public link of the doc document.
这5个函数在同一个应用程序脚本中使用“全局”函数顺序执行,该函数允许我检索文件夹的ID和创建的文档我使用cURL运行此应用程序脚本(从终端)
脚本的持续时间约为10秒,我想知道是否有可能在每个函数完成时得到更新的消息(或文本值)作为响应
我在互联网上和Stackoverflow上查找过,但我发现的所有内容都涉及到在电子表格中使用“flush”命令来更新单元格的值。我需要的是更新终端中的响应消息
谁能帮帮我吗
多谢各位
典狱长从您的以下职能中 职能1。-创建新文件夹并检索ID。 职能2。-在文件夹中创建文档文件的副本。 职能3。-替换文档中{{text}}类型的几个标记的文本。 职能4在文档中插入图像。 职能5检索文档的公共链接 我认为在您的情况下,可以使用以下3种模式
- 在这种情况下,您的
无法实现目标我想知道是否有可能在响应中获得消息(或文本值),并在每个功能完成时更新。
- 为了在每个函数完成时检索响应,每次都使用curl命令执行每个函数。这一点我已经提过了
- 在这种情况下,不需要使用全局变量。为了检索响应,每次都使用curl命令执行每个函数。但是,当执行每个函数时,需要将每个响应值提供给下一个函数。我想这可能有点复杂
- 在这种情况下,不需要使用全局变量。并且,文件夹ID和文档ID在每个函数运行期间放置和获取。这样,可以使用curl命令按顺序运行每个函数。因此,我认为使用curl命令的脚本可能会变得有点简单
// Create a new folder and retrieve the ID.
function function1() {
const folderId = DriveApp.createFolder("sampleFolder").getId();
PropertiesService.getScriptProperties().setProperty("folderId", folderId);
return "Function1: Done.";
}
// Create a copy of a doc file in the folder.
function function2() {
const folderId = PropertiesService.getScriptProperties().getProperty("folderId");
const folder = DriveApp.getFolderById(folderId);
const documentId = DocumentApp.create("sampleDocument").getId();
DriveApp.getFileById(documentId).moveTo(folder);
PropertiesService.getScriptProperties().setProperty("documentId", documentId);
return "Function2: Done.";
}
function function3() {
const documentId = PropertiesService.getScriptProperties().getProperty("documentId");
// do something
return "Function3: Done.";
}
function function4() {
const documentId = PropertiesService.getScriptProperties().getProperty("documentId");
// do something
return "Function4: Done.";
}
function function5() {
const documentId = PropertiesService.getScriptProperties().getProperty("documentId");
// do something
return "Function5: Done.";
}
- 在这个示例脚本中,在每个函数运行期间放置和获取文件夹ID和文档ID
- 在此示例脚本中,不包括错误处理。所以当你使用这个时,请添加它
#!/bin/sh
accessToken="###your access token###"
url="https://script.googleapis.com/v1/scripts/###your script ID###:run"
curl -X POST -H "Authorization: Bearer ${accessToken}" -H "Content-Type: application/json" -d "{\"function\": \"function1\", devMode: true}" ${url}
curl -X POST -H "Authorization: Bearer ${accessToken}" -H "Content-Type: application/json" -d "{\"function\": \"function2\", devMode: true}" ${url}
curl -X POST -H "Authorization: Bearer ${accessToken}" -H "Content-Type: application/json" -d "{\"function\": \"function3\", devMode: true}" ${url}
curl -X POST -H "Authorization: Bearer ${accessToken}" -H "Content-Type: application/json" -d "{\"function\": \"function4\", devMode: true}" ${url}
curl -X POST -H "Authorization: Bearer ${accessToken}" -H "Content-Type: application/json" -d "{\"function\": \"function5\", devMode: true}" ${url}
当运行上述脚本时,将获得以下结果
{
"done": true,
"response": {
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse",
"result": "Function1: Done."
}
}
{
"done": true,
"response": {
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse",
"result": "Function2: Done."
}
}
{
"done": true,
"response": {
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse",
"result": "Function3: Done."
}
}
{
"done": true,
"response": {
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse",
"result": "Function4: Done."
}
}
{
"done": true,
"response": {
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionResponse",
"result": "Function5: Done."
}
}
当然,作为测试,您还可以手动运行每个curl命令
注:
- 在这个答案中,假设您已经能够使用Google Apps脚本API执行Google Apps脚本项目的功能。请小心这个