服务不可用:复制 Google 文档时出现 DOCS

Iva*_*vix 5 google-docs google-apps-script

突然遇到一个问题,Google DOCS 服务在调用一些复制元素后失败。有趣的是,它实际上复制了第一个元素,但是当它进入“for”中的第二个循环时,它无法给出以下错误:服务不可用:文档

这个脚本曾经可以正常工作几个月,因为我们在公司内发布了它。上周突然它停止为所有用户工作,无论他们的浏览器等如何......

它是一个链接到 Google 电子表格的脚本(它从中获取信息以生成 Google 文档)。但是,如果我也从脚本控制台执行或调试它,它也会失败。

在它开始失败后我尝试过的是添加几行来 saveAndClose 文档,以防出现过多调用或缓冲的问题。

我已经检查过,该项目确实可以访问 Google Docs、Drive 和 Maps API。

要复制的元素是正确的,因为我可以用它们做 Logger.Log...

它只是在必须复制实际元素(appendParagraph、append ListItem 等)时失败

我启用了 StackDriver 日志和错误,但它没有在控制台中显示任何日志,只是“失败”。

任何提示或指示将非常感谢!

谢谢!

function copyDescription(ID,newDoc,newDocID){
var otherBody = DocumentApp.openById(ID).getBody();
newDoc.saveAndClose();
newDoc = DocumentApp.openById(newDocID);
var docbody = newDoc.getBody();

var totalElements = otherBody.getNumChildren();


//Run through template document and copies to the new one
for( var j = 0; j < totalElements; ++j ) {
    var element = otherBody.getChild(j).copy();
    var attributes = otherBody.getChild(j).getAttributes();
    var type = element.getType();


    if (type == DocumentApp.ElementType.PARAGRAPH) {
        if (element.asParagraph().getNumChildren() != 0 && element.asParagraph().getChild(0).getType() == DocumentApp.ElementType.INLINE_IMAGE) {
            var pictattr = element.asParagraph().getChild(0).asInlineImage().getAttributes();
            var blob = element.asParagraph().getChild(0).asInlineImage().getBlob();
        }
        else { 
            docbody.appendParagraph(element);
        }
    }
    else if( type == DocumentApp.ElementType.TABLE )
        docbody.appendTable(element);
    else if( type == DocumentApp.ElementType.LIST_ITEM )
        docbody.appendListItem(element);
    else
        throw new Error("Unsupported element type: "+type);

    newDoc.saveAndClose();
}
Run Code Online (Sandbox Code Playgroud)

}