我每天都会每分钟收到错误通知,如下所示 / * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * * 您的脚本,订阅观众的更改:衣服和配件,最近未能成功完成。故障摘要如下所示。要配置此脚本的触发器,或更改接收未来失败通知的设置,请单击此处。
文档使用该脚本订阅观众的更改:衣服和配件。
详细说明: 启动功能错误消息触发结束 发送更改需要授权才能执行该操作。基于时间的6/28/12 9:08 PM
此致
Google Apps脚本
需要帮助?访问Google Apps脚本文档。请不要回复这个信息。 (c)2012年谷歌 的 * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** / 这是该错误的相关代码
/ * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ***
var ss = SpreadsheetApp.getActiveSpreadsheet();
function send_changes() {
var current_time = new Date();
var last_check = ScriptProperties.getProperty("last_check");
if (last_check == null) {
last_check = current_time;
ScriptProperties.setProperty("last_check", last_check);
}
var updates = '';
var url = ss.getSheetByName('Dashboard').getRange('C5').getValue();
var when = ss.getSheetByName('Dashboard').getRange('C8').getValue();
var scope = ss.getSheetByName('Dashboard').getRange('C3').getValue();
if (scope == 'Site') {
var site = SitesApp.getSiteByUrl(url);
var descendants = site.getAllDescendants();
for (var j = 0; j < descendants.length; j++) {
var updates = getInfo_(descendants[j], updates, last_check, when);
}
}
else if (scope == 'Page and all subpages') {
var page = SitesApp.getPageByUrl(url);
var descendants = page.getAllDescendants();
for (var j = 0; j < descendants.length; j++) {
var updates = getInfo_(descendants[j], updates, last_check, when);
}
}
else {
var page = SitesApp.getPageByUrl(url);
var updates = getInfo_(page, updates, last_check, when);
}
if (updates != "") {
updates = updates.replace(/<td>/g, "<td style=\"border: 1px solid grey; padding: 7px;\">");
updates = updates.replace(/<th>/g, "<th colspan=2 BGCOLOR='#0066cc' style=\"border: 1px solid grey; padding: 10px; text-align: left; color: white; font-size: 1.1em;\">");
updates = updates.replace(/<table>/g, "<table style=\"width: 700px; border-collapse: collapse;\">");
// Remove duplicates, remove people who have unsubscribed, remove false email addresses
var mailing = scrubData_();
var subject = ss.getSheetByName('Dashboard').getRange('G5').getValue();
///////////////////////////////////////////////////////////////////////////////////
// If the number of updates is too important, send those updates as attachment
///////////////////////////////////////////////////////////////////////////////////
if (updates.length * 2 > 19800) {
var body = ss.getSheetByName('Dashboard').getRange('G7').getValue() + "<br><br>";
body += "*** You can find those updates in attachment. ***";
body += "<br><br><a href=\"" + ss.getFormUrl() + "\">Unsubscribe</a>";
}
else {
var body = ss.getSheetByName('Dashboard').getRange('G7').getValue() + "<br><br>" + updates;
body += "<br><br><a href=\"" + ss.getFormUrl() + "\">Unsubscribe</a>";
}
////////////////////
// Batch emails
////////////////////
for (var j = 0; j < mailing.length; j = j + 30) {
var bcc = "";
for (var k = j; k < j + 30; k++) {
if (k < mailing.length && mailing[k][1] != "") {
bcc += mailing[k][1] + ",";
}
}
if (updates.length * 2 > 19800) {
MailApp.sendEmail('notify@google.com', subject, body, {
bcc: bcc,
htmlBody: body,
attachments: [Utilities.newBlob(updates, "text/html", "Updates")]
});
}
else {
MailApp.sendEmail('notify@google.com', subject, body, {
bcc: bcc,
htmlBody: body
});
}
}
var emails_sent = ss.getSheetByName('Dashboard').getRange('G17').getValue();
ss.getSheetByName('Dashboard').getRange('G17').setValue(emails_sent + 1);
}
ScriptProperties.setProperty("last_check", current_time);
}
function getInfo_(page, updates, last_check, when) {
var type = page.getPageType();
switch (type.toString()) {
case 'AnnouncementsPage':
var newsfeed = page.getAnnouncements();
for (var j = 0; j < newsfeed.length; j++) {
if (chooseWhen_(newsfeed[j], when) > new Date(last_check).getTime()) {
updates += "<table><tr><th>" + newsfeed[j].getTitle() + "</th></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Blog </td><td>" + page.getTitle() + "</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Preview </td><td style=\"color: grey; font-style: italic; border: 1px solid grey; padding: 7px;\">" + newsfeed[j].getTextContent().substr(0, 280) + "...</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Link </td><td><a href=\"" + newsfeed[j].getUrl() + "\">Link</a></td></tr></table><br>";
}
}
break;
case 'FileCabinetPage':
var attachments = page.getAttachments();
for (var j = 0; j < attachments.length; j++) {
if (chooseWhen_(attachments[j], when) > new Date(last_check).getTime()) {
updates += "<table><tr><th>" + attachments[j].getTitle() + "</th></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Type </td><td>Attachment</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Description </td><td>" + attachments[j].getDescription() + "</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Page </td><td>" + page.getTitle(); + "</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Link </td><td><a href=\"" + page.getUrl() + "\">Link</a></td></tr></table><br>";
}
}
break;
case 'ListPage':
var listItems = page.getListItems();
var listUpdated = false;
for (var j = 0; j < listItems.length; j++) {
if (chooseWhen_(listItems[j], when) > new Date(last_check).getTime()) {
listUpdated = true;
}
}
if (listUpdated) {
updates += "<table><tr><th>" + page.getTitle() + "</th></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">List </td><td style=\"color: grey; font-style: italic; border: 1px solid grey; padding: 7px;\">New item added</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Link </td><td><a href=\"" + page.getUrl() + "\">Link</a></td></tr></table><br>";
}
break;
case 'WebPage':
if (chooseWhen_(page, when) > new Date(last_check).getTime()) {
updates += "<table><tr><th>" + page.getTitle() + "</th></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Preview </td><td style=\"color: grey; font-style: italic; border: 1px solid grey; padding: 7px;\">" + page.getTextContent().substr(0, 280) + "...</td></tr>";
updates += "<tr><td style=\"border: 1px solid grey; padding: 7px; width: 100px;\">Link </td><td><a href=\"" + page.getUrl() + "\">Link</a></td></tr></table><br>";
}
break;
}
return updates;
}
function chooseWhen_(item, when) {
var time = 0;
if (when == 'Item is updated') {
time = item.getLastUpdated().getTime();
}
else {
time = item.getDatePublished().getTime();
}
return time;
}
的 的 ** * ** * ** * 的** * ** * ** * ** * ** * 的** * ** * ** * ** * ** * 的** * ** * ** * **** /
答案 0 :(得分:1)
脚本错误通知明确指出“执行该操作需要授权” 因此,打开脚本编辑器(作为已安装此触发器的用户) 并从脚本编辑器运行任何功能 - 然后它会要求您授权。允许之后,您不应再看到这些错误。
请注意,某些服务(如Mail)要求您在每次修改脚本时重新授权(即使添加空格并将保存视为修改)。
答案 1 :(得分:0)
我可以提出几点建议:
getActiveSpreadsheet()
并将其替换为openById('SSkey')
答案 2 :(得分:0)
启动功能错误消息触发结束 7/10/12 9:08 PM send_changes执行该操作需要授权。基于时间的7/10/12 9:08 PM
错误信息来自send_changes函数,我运行send_changes函数,它要求授权,我也接受授权。但仍然每分钟都会出现错误通知。请给我一个解决这个问题的永久解决方案。