尝试向Google文档中添加编辑器时出现Google Apps脚本服务器错误 [英] Google Apps Script server error when trying to add an editor to a Google Document
问题描述
我有一些看起来像这样的代码
I have some code that looks like this
var folder = DriveApp.getFolderById(/* destination folder id */);
var doc = DriveApp.getFileById(/* document file id */);
var id = doc.makeCopy(folder).setName(/* name of copy */).getId();
var new_doc = DocumentApp.openById(id);
new_doc.addEditor(/* some email address */);
运行此命令将导致脚本在最后一行停止并抛出此错误:
Running this causes the script to stop at the last line and throw this error:
很抱歉,发生服务器错误.请稍等,然后重试.
We're sorry, a server error occurred. Please wait a bit and try again.
如果我注释掉这一行,那么脚本可以正常运行.
如果显然,它对于new_doc
是File
而不是Document
,那么最后一行也可以正常工作.只有当new_doc
是Document
类型时,它才会给我一个错误.Document
类型也不起作用.尽管我得到的错误与File
:
If I comment out the line, then the script runs fine.
Also if Apparently, it doesn't work for new_doc
is a File
instead of a Document
, then the last line works fine too. It's only when new_doc
is a Document
type that it gives me an error.Document
types either. Although the error I get is different from when it's a File
:
不能在Team Drive项目上使用此操作.
Cannot use this operation on a Team Drive item.
很奇怪,因为这在前一段时间起作用.
Very weird, because this was working a while ago.
此脚本中使用的所有资源(脚本,目标文件夹,要复制的文件,副本等)都位于Team Drive中.
All resources used in this script (the script, the destination folder, the file that is copied, the copy, etc.) are in a Team Drive.
对于如何或为什么发生此错误,我感到困惑,我正在寻求帮助来解决此问题.
I am puzzled as to how or why this error is happening and I am looking for help in getting around this issue.
推荐答案
通过DriveApp添加编辑器,而不是通过DocumentApp添加编辑器.
Add the editor through the DriveApp as opposed to the DocumentApp.
在使用Team Drive文件时,这似乎是DocumentApp,SpreadsheetApp和FormApp的错误.
It appears to be a bug with DocumentApp, SpreadsheetApp and FormApp when working with Team Drive files.
var folder = DriveApp.getFolderById(/* destination folder id */);
var doc = DriveApp.getFileById(/* document file id */);
var id = doc.makeCopy(folder).setName(/* name of copy */).getId();
var new_doc = DriveApp.getFileById(id); //updated this from DocumentApp to DriveApp.
new_doc.addEditor(/* some email address */);
这篇关于尝试向Google文档中添加编辑器时出现Google Apps脚本服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!