您好我一直收到此错误,我需要解决它。我想要做的是将我的推特链接到rss feed。
“第6923行第1行的错误:打开和结束标记不匹配:img第0行和标题”
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);
}
答案 0 :(得分:0)
您应该在第6923行的第1行显示XML代码。
它打赌它在标题中有一个特殊字符的问题。请参阅how to escape xml entities in javascript?(我认为您的代码是JS)