Google脚本错误:您无权调用openById [英] Google Script Error: You do not have permission to call openById

查看:865
本文介绍了Google脚本错误:您无权调用openById的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var file = 

我试图发送一封邮件,附上我的谷歌驱动器中可用的文件, DriveApp.getFileById( '1qZVK0UZ1jLbDdj10FXZqeAVEodvxEy2Bs');
MailApp.sendEmail('xyz@gmail.com','subject','body',{attachments [file.getAs(MimeType.PDF)]});

当我在脚本上面手动运行时,它运行正常,电子邮件被发送。但是,当我使用表单提交触发器运行它时,它会给出错误您没有权限调用openById



会重现问题的步骤?


  1. 创建一个Google表单。

  2. 在脚本编辑器中编写上面的脚本并添加一个提交表单的触发器。 li>
  3. 填写并提交表单,然后您将从'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?

  1. create a google form.
  2. write above scripts on script editor and add a trigger with submission of the form.
  3. 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屋!

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