在 gmail 插件中授予权限
Give permission in a gmail addon
我正在尝试在 Google Apps 脚本插件中为 Gmail 编写一个脚本,它将在周末回复所有电子邮件并显示外出消息:
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var daysOff = [5]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var date = new Date();
var day = date.getDay();
var label = GmailApp.getUserLabelByName("autoresponded");
if (daysOff.indexOf(day) > -1) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox !label:autoresponded after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
var message = threads[i].getMessages()[0];
if (message.getFrom().indexOf("myemail@gmail.com") < 0 && message.getFrom().indexOf("no-repl") < 0 && message.getFrom().indexOf("bounce") < 0 && message.getFrom().indexOf("spam") < 0) {
threads[i].reply("", {
htmlBody: "<p>Thank you for your message. We will get back to you as soon as possible. </p>"
});
label.addToThread(threads[i]);
}
}
}
}
但是我一直收到这个错误:
Exception: The script does not have permission to perform that action. Required permissions: (https://www.googleapis.com/auth/gmail.labels || https://www.googleapis.com/auth/gmail.metadata || https://www.googleapis.com/auth/gmail.readonly || https://www.googleapis.com/auth/gmail.modify || https://mail.google.com/)
这是在我在 Gmail 中为我的 Gmail 帐户授予权限后发生的。我在这里缺少什么吗?这是要经过的另一层?
我尝试删除附加组件并重新授予 Gmail 权限,但没有成功。附加组件的触发器是每 5 分钟一次,就像脚本中的间隔一样。
我尝试转到错误中的链接,但他们只是想出了空白页。
您必须在 Google Apps 脚本项目清单中设置 OAuth 范围。
Verify the add-on OAuth scopes
Scopes define what actions the add-on is allowed to take on a user's behalf. It's a best practice for add-ons to only have scopes for actions they must have in order function and nothing more.
In add-on projects, explicitly set the add-on scopes in order to ensure the add-on uses the least-permissive set of scopes possible. You define what scopes your add-on uses in the add-on manifest.
See Scopes for more details.
我正在尝试在 Google Apps 脚本插件中为 Gmail 编写一个脚本,它将在周末回复所有电子邮件并显示外出消息:
function autoReply() {
var interval = 5; // if the script runs every 5 minutes; change otherwise
var daysOff = [5]; // 1=Mo, 2=Tu, 3=We, 4=Th, 5=Fr, 6=Sa, 0=Su
var date = new Date();
var day = date.getDay();
var label = GmailApp.getUserLabelByName("autoresponded");
if (daysOff.indexOf(day) > -1) {
var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
var threads = GmailApp.search('is:inbox !label:autoresponded after:' + timeFrom);
for (var i = 0; i < threads.length; i++) {
var message = threads[i].getMessages()[0];
if (message.getFrom().indexOf("myemail@gmail.com") < 0 && message.getFrom().indexOf("no-repl") < 0 && message.getFrom().indexOf("bounce") < 0 && message.getFrom().indexOf("spam") < 0) {
threads[i].reply("", {
htmlBody: "<p>Thank you for your message. We will get back to you as soon as possible. </p>"
});
label.addToThread(threads[i]);
}
}
}
}
但是我一直收到这个错误:
Exception: The script does not have permission to perform that action. Required permissions:
(https://www.googleapis.com/auth/gmail.labels || https://www.googleapis.com/auth/gmail.metadata || https://www.googleapis.com/auth/gmail.readonly || https://www.googleapis.com/auth/gmail.modify || https://mail.google.com/)
这是在我在 Gmail 中为我的 Gmail 帐户授予权限后发生的。我在这里缺少什么吗?这是要经过的另一层?
我尝试删除附加组件并重新授予 Gmail 权限,但没有成功。附加组件的触发器是每 5 分钟一次,就像脚本中的间隔一样。 我尝试转到错误中的链接,但他们只是想出了空白页。
您必须在 Google Apps 脚本项目清单中设置 OAuth 范围。
Verify the add-on OAuth scopes
Scopes define what actions the add-on is allowed to take on a user's behalf. It's a best practice for add-ons to only have scopes for actions they must have in order function and nothing more.In add-on projects, explicitly set the add-on scopes in order to ensure the add-on uses the least-permissive set of scopes possible. You define what scopes your add-on uses in the add-on manifest.
See Scopes for more details.