Google脚本错误:您无权调用openById [英] Google Script Error: You do not have permission to call openById
问题描述
var file = 我试图发送一封邮件,附上我的谷歌驱动器中可用的文件, DriveApp.getFileById( '1qZVK0UZ1jLbDdj10FXZqeAVEodvxEy2Bs');
MailApp.sendEmail('xyz@gmail.com','subject','body',{attachments [file.getAs(MimeType.PDF)]});
当我在脚本上面手动运行时,它运行正常,电子邮件被发送。但是,当我使用表单提交触发器运行它时,它会给出错误您没有权限调用openById
会重现问题的步骤?
- 创建一个Google表单。
- 在脚本编辑器中编写上面的脚本并添加一个提交表单的触发器。 li>
- 填写并提交表单,然后您将从'apps-scripts-notifications@google.com'收到上述错误邮件。
请帮助。
在Form本身上创建脚本时发现此问题。
为了解决这个问题,您首先需要将回复发送到电子表格。 从你的表单转到工具>脚本编辑器... 复制你的脚本并删除你在那里设置的所有触发器,不再需要这个脚本。
现在点击表单中的查看回复按钮即可打开电子表格。
现在将您的触发器设置为正常。你会发现新的触发器的第三个下拉列表中有表单提交选项。
一旦表单提交后您的脚本被授权,该事件将触发并可访问DriveApp。
一旦你测试了并且能够正常工作,我会回到表单并删除那里的脚本项目。我这样做是为了保持整洁并避免混淆,如果我稍后改变脚本并忘记哪一个实际上是活的。
我不知道是否存在Google表单的限制限制了他们访问云端硬盘或其他内容。
I am trying to send a mail with attaching a file available in my google drive using following google scripts
var file=DriveApp.getFileById('1qZVK0UZ1jLbDdj10FXZqeAVEodvxEy2Bs');
MailApp.sendEmail('xyz@gmail.com','subject','body',{attachments[file.getAs(MimeType.PDF)]});
when I run above script manually it runs fine, email gets sent. But when I run it using form Submission trigger it gives error "You do not have permission to call openById"
steps that will reproduce the problem?
- create a google form.
- write above scripts on script editor and add a trigger with submission of the form.
- fill and submit the form then you will get above error into mail from 'apps-scripts-notifications@google.com'
Please help.
I found this when creating the script on the Form itself.
To solve the problem first have you form responses sent to a spreadsheet.
From you form go to Tools > Script editor... copy you script and delete any triggers you have set up there, you won't be needing this script anymore.
Now click on View responses button in your form to open the spreadsheet.
- Go to Tools > Script editor... (for the spreadsheet).
- You should start with a blank project.
- Delete anything in there and paste in your script.
- Save and name you project.
Now set up your triggers as normal. You will find the third drop down list of the new trigger has the option On form submit.
Once your script is authorised any time the form is submitted the event will trigger and will have access to the DriveApp.
Once you've tested and got it working I would go back to the form and delete the script project in there. I do that to keep things tidy and save confusion if I come to alter the script later and have forgotten which one is actually live.
I don't know if there is a limitation with Google Forms that limits their access to Drive or something.
这篇关于Google脚本错误:您无权调用openById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!