尝试运行以下代码时出现错误error on line 1 at column 1: Document is empty
。可能导致什么呢?
function Twitter_RSS() {
return;
}
function doGet(e) {
var widgetID = e.queryString? e.queryString : "ERROR_NO_ID_FOUND";
var cache = CacheService.getPublicCache();
var id = "Twitter" + widgetID;
var rss = cache.get(id);
if ( ! rss ) {
rss = getTweets(widgetID);
cache.put(id, rss, 120); // Expire in 2 minutes
}
return ContentService.createTextOutput(rss)
.setMimeType(ContentService.MimeType.XML);
}
function getTweets(id) {
try {
var widget, json, tweets, regex, tweet, list, time, url, when, rss, heading, title, link, alltweets, permalink, permatitle;
title = "Twitter RSS Feed : " + id;
link = "http://www.techcovered.org/#" + id;
url = "http://cdn.syndication.twimg.com/widgets/timelines/" + id;
widget = UrlFetchApp.fetch(url);
json = Utilities.jsonParse(widget);
if ( ! json.body ) {
return;
}
list = json.body.replace(/(\r\n|\n|\r)/gm," ")
.replace(/\s+/g, " ")
.replace(/<div class=\"(h-card|footer|detail-expander|retweet-credit)[^>]*>(.*?)<\/div>/gi, "")
.replace(/<time[^>]*>(.*?)<\/time>/gi, "");
regex = new RegExp(/<h1[^>]*>(.*?)<\/h1>/ig);
if ((heading = regex.exec(list)) !== null) {
regex = RegExp(/href="(.*?)"/ig);
if ((permalink = regex.exec(heading[1])) !== null) {
link = permalink[1];
}
regex = RegExp(/title="(.*?)"/ig);
if ((permatitle = regex.exec(heading[1])) !== null) {
title = permatitle[1];
}
}
var self = ScriptApp.getService().getUrl() + "?" + id;
rss = '<?xml version="1.0"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
rss += ' <channel><title>' + title + '</title>';
rss += ' <link>' + link + '</link>';
rss += ' <atom:link href="' + self + '" rel="self" type="application/rss+xml" />';
rss += ' <description>' + title + ' :: RSS Generator available at http://www.labnol.org/?p=28149</description>';
regex = RegExp(/<ol[^>]*>(.*?)<\/ol>/ig);
if ((alltweets = regex.exec(list)) !== null) {
alltweets = alltweets[1].replace(/\s+/g, " ");
var re = /<a class=".*?permalink.*?" href="(.*?)" data-datetime="(.*?)"[^>]*>(.*?)<\/a>(.*?)<p[^>]*>(.*?)<\/p>/gm;
while (tweet = re.exec(alltweets)) {
url = tweet[1];
when = Utilities.formatDate(parseDate(tweet[2]), "UTC", "EEE, d MMM yyyy HH:mm:ss");
tweet = tweet[5].replace(/<\s*(div|span|b|p)[^>]*>/gi, "")
.replace(/<\s*\/\s*(div|span|b|p)[^>]*>/gi, "")
.replace(/class=".*?"|rel=".*?"|title=".*?"|target=".*?"|data-expanded-url=".*?"|data-query-source=".*?"|dir=".*?"|data-scribe=".*?"/gi, "")
.replace(/\s+/g, " ");
if(tweet.substring(0,2)!="RT") {
rss += "<item>";
rss += " <title>"+ tweet.replace(/<a[^>]*>(.*?)<\/a>/gi, "") + "</title>";
rss += " <pubDate>" + when + " +0000</pubDate>";
rss += " <guid>" + url + "</guid>";
rss += " <link>" + url + "</link>";
rss += " <description><![CDATA[ @"+url.split("/")[3] + ": " + tweet + "]]></description>";
rss += "</item>";
}
}
rss += "</channel></rss>";
return rss;
}
} catch (e) {
Logger.log(e.toString());
}
}
function parseDate(d) {
var date = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/;
var m = date.exec(d);
var year = +m[1];
var month = +m[2];
var day = +m[3];
var hour = +m[4];
var minute = +m[5];
var second = +m[6];
return new Date(year, month - 1, day, hour, minute, second);
}