我很抱歉,如果这个问题太简单,但我是一个新手使用cURL。我在Google App Script中创建了一个函数,用于合并两个Google文档中的文本。函数如下:
function mergeGoogleDocs(doc1, doc2) {
var BaseDoc = DocumentApp.openById(doc1);
var body = BaseDoc.getActiveSection();
var otherBody = DocumentApp.openById(doc2).getActiveSection();
var totalElements = otherBody.getNumChildren();
for( var j = 0; j < totalElements; ++j ) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if( type == DocumentApp.ElementType.PARAGRAPH )
{
body.appendParagraph(element);
}
else if( type == DocumentApp.ElementType.TABLE )
{
body.appendTable(element);
}
else if( type == DocumentApp.ElementType.LIST_ITEM )
{
body.appendListItem(element);
}
else
{
throw new Error("Error de Formato: "+type);
}
}
}
我已经测试了脚本,如果我把两个document-ID,它可以完美地工作。我希望能够调用这个功能从外部谷歌使用cURL。为此,我启用了所有必要的(凭证,范围权限,项目编号并将其实现为可执行API)。我一直在寻找用cURL运行函数的方法,只在这个post中找到了这个:
curl -X POST -L \
-H "Authorization: Bearer ### access token ###" \
-H "Content-Type: application/json" \
-d "{function: '### function name ###',devMode: true}" \
"https://script.googleapis.com/v1/scripts/### script ID ###:run"
我需要包含两个document_IDs
作为参数,因此根据上一篇文章中的信息,我创建了以下序列:
curl -X POST -L \
-H 'Authorization: Bearer ##access token##' \
-H "Content-Type: application/json" \
-d '{"function": "##function name##", "parameters": {"doc1":"##docID1##,"doc2":"##docID2##"}, devMode: true}' \
"https://script.googleapis.com/v1/scripts/### script ID ###:run"
但是当我运行序列时,我得到这个错误消息:
{
"done": true,
"error": {
"code": 3,
"message": "ScriptError",
"details": [
{
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionError",
"scriptStackTraceElements": [
{
"function": "##function name##",
"lineNumber": 3
}
],
"errorMessage": "Exception: Document is missing (perhaps it was deleted, or you don't have read access?)",
"errorType": "ScriptError"
}
]
}
}
有人可以帮助我把顺序正确的应用程序脚本工作吗?.
1条答案
按热度按时间jljoyd4f1#
我相信你的目标和你目前的情况如下。
##docID1##
和##docID2##
的值指定给Google Apps Script项目中的mergeGoogleDocs(doc1, doc2)
函数。修改要点:
function mergeGoogleDocs(doc1, doc2) {}
给予2个参数,请将##docID1##
和##docID2##
的值提供给parameters
的数组,如"parameters": ["##docID1##", "##docID2##"]
。在这种情况下,当使用"parameters": ["##docID1##", "##docID2##"]
时,数组的每个元素都对应于Google Apps Script中函数的每个参数。##docID1##
和##docID2##
的值作为mergeGoogleDocs(doc1, doc2)
的参数,请设置像"parameters": ["##docID1##", "##docID2##"]
这样的值。{"doc1":"##docID1##,"doc2":"##docID2##"}
时,"##docID1##
没有被封闭。当上面的点被反射到curl命令时,它变成如下所示。
修改curl命令:
注意:
{"doc1":"##docID1##","doc2":"##docID2##"}
作为arcuments时,你也可以使用下面的curl命令。"parameters": "value"
。也就是说,我确认了"parameters": "value"
的结果与"parameters": ["value"]
的结果相同。参考: