我每天每分钟都会收到错误通知,如下所示 / * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * * * * ** * * 您的脚本“为观众订阅更改:服装和配饰”最近未能成功完成。故障摘要如下所示。要为此脚本配置触发器,或更改您的设置以接收未来的失败通知,请单击此处。
该脚本由文档为查看者订阅更改使用:衣服和配饰。
详细信息:启动函数错误消息触发器结束 2012 年 6 月 28 日晚上 9:08 send_changes 执行该操作需要授权。基于时间的 2012 年 6 月 28 日晚上 9:08
真挚地,
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;
}
** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** ** /