在脚本编辑器中批准了Apps-Script电子邮件许可权,但未在工作表中批准? [英] Apps-Script email permissions approved in script editor, but not in sheet?

查看:88
本文介绍了在脚本编辑器中批准了Apps-Script电子邮件许可权,但未在工作表中批准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Enterprise(以防万一).

I am using Google Enterprise (in case that makes a difference).

我用一个非常短的脚本制作了一个电子表格,其中只有两个功能,一个用于计算我称为unread_emails()的未读gmail邮件的数量,另一个是将当前时间复制到电子表格单元格的onOpen()脚本(因此我知道它正在运行),然后调用第一个函数并将其结果复制到电子表格中.

I have made a spreadsheet with a very short script, just two functions, one that counts the # of unread gmail mails which I called unread_emails(), and an onOpen() script that copies the current time to a spreadsheet cell (so I know that it's running) and then calls the first function and copies its result to the spreadsheet.

当我第一次从脚本编辑器"运行此脚本时,它向我询问权限,然后单击确定".从那时起,如果我从脚本编辑器启动该脚本,该脚本将始终运行完美,并且不再要求权限. -如果我只是打开电子表格,由于getInboxUnreadCount()上的权限错误,onOpen()函数将部分停止运行–即使我已经授予了权限,并且它显然正在我的帐户上运行(不,它也不会要求我仅重新确认我的权限).如果我重新打开脚本编辑器,一切运行正常.

When I first ran this from the Script Editor, it asked me for permissions, and I clicked okay. Since then, the script always runs perfectly if I launch it from the Script Editor, and no longer asks for permissions. BUT -- if I just open the spreadsheet, the onOpen() function will be halted part-way through, by a permissions error on getInboxUnreadCount() -- even though I've already given permission, and it's clearly running on my account (and no, it doesn't ask me to simply re-affirm my permissions, either). If I re-open the Script Editor, everything runs fine.

如何获取Google表格以识别此处已分配的权限? 任何见解将不胜感激.

How can I get Google Sheets to recognize the permissions that are already assigned here? Any insights would be greatly appreciated.

这是简单的脚本.第三行的GmailApp显然是麻烦的根源.

Here is the simple script. The GmailApp at line 3 is the apparent source of troubles.

function unread_mails() {
  Logger.log("starting unanswered func");
  return GmailApp.getInboxUnreadCount();
}

function onOpen() {
  Logger.log("starting onOpen func");
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheets()[0];
  var d = new Date();
  sheet.getRange("B4").setValue(0); // clear
  sheet.getRange('B2').setValue(d.toLocaleTimeString());
  sheet.getRange("B4").setValue(unread_mails());
}

推荐答案

来自简单的触发限制:

他们无法访问需要授权的服务.例如,一个 简单触发器无法发送电子邮件,因为Gmail服务需要 授权

They cannot access services that require authorization. For example, a simple trigger cannot send an email because the Gmail service requires authorization

它可以在编辑器中运行,手动运行onOpen()的b/c不同于自动触发简单触发器的方法

it works from the editor, b/c running onOpen() manually isn't the same as having the simple trigger fire off automatically

这篇关于在脚本编辑器中批准了Apps-Script电子邮件许可权,但未在工作表中批准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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