从Google表单提交生成Google文档时出现OpenById错误 [英] OpenById Error when generate Google Doc from Google Form Submission

查看:154
本文介绍了从Google表单提交生成Google文档时出现OpenById错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在Google教育网域中工作,我想通过Google表单的onSubmit触发器自动生成Google文档.我有一个要复制的模板文件,然后用表单中的回复替换字段(例如{{name}}).

I am currently working in a Google Education domain and I would like to automatically generate a Google Doc via an onSubmit trigger from a Google Form. I have a template file that I would like to copy and then replace fields (e.g., {{name}}) with responses from the form.

提交后,模板Google文档已成功复制并重命名,但是我无法打开该文档来替换文本字段.

Upon submission, the template Google doc is successfully copied and renamed, but I cannot open the doc to replace the text fields.

var templateFile = DriveApp.getFileById(id);
var targetFolder = DriveApp.getFolderById(id);
var newDocName = title + "_" + name + "_" + submissionDate;
var newFile = templateFile.makeCopy(newDocName, targetFolder);
var newFileId = newFile.getId();
var doc = DocumentApp.openById(newFileId);
var body = doc.getBody();

该文档已复制并重命名,但在"DocumentApp.openById"处引发错误

The doc is copied and renamed, but throws an error at "DocumentApp.openById"

您无权调用DocumentApp.openById.必需的权限:onSubmit(代码为 https://www.googleapis.com/auth/documents :81)

You do not have permission to call DocumentApp.openById. Required permissions: https://www.googleapis.com/auth/documents at onSubmit(Code:81)

我不知道为什么,因为我是表单和模板的所有者!

I don't know why because I am the owner of both the form and the template!

推荐答案

正如一位用户所说,您需要至少直接从编辑器中运行一次代码(该函数).这将提示您oauth同意屏幕,以便您可以授权代码所需的范围(在这种情况下为drive和docs API范围),并使用这些范围更新您的项目.

As one user said, you need to run the code (the function) directly from the editor at least once. This will prompt you the oauth consent screen so you can authorize the scopes needed for your code (drive and docs API scopes, in this case) and will update your project with these scopes.

这篇关于从Google表单提交生成Google文档时出现OpenById错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆