OpenById Error when generate Google Doc from Google Form Submission

[亡魂溺海] 提交于 2019-12-01 12:45:38

问题


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.

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();

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

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!


回答1:


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.



来源:https://stackoverflow.com/questions/57138197/openbyid-error-when-generate-google-doc-from-google-form-submission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!