Google Apps脚本RSS输出 [英] Google Apps Script RSS Output

查看:79
本文介绍了Google Apps脚本RSS输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Apps脚本从日历中输出即将发生的事件的格式化RSS提要,然后将其插入Mailchimp模板中.

I am trying to use Google Apps Script to output a formatted RSS feed of upcoming events from a calendar that I can then insert into a Mailchimp Template.

这是我用来生成rss提要的HTML:

This is the HTML I am using to generate the rss feed:

<rss version="2.0">
<channel>
  <title><?= "Title" ?></title>
  <?   var cal = CalendarApp.getCalendarById('CalendarID');
       var today = new Date();
       var future = today.addDays(90); //Uses separate function to add days to look ahead
       var events = cal.getEvents(today, future);
     for (var t in events) { ?>
     <item>
        <? var start = new Date(events[t].getStartTime())
           var date = Utilities.formatDate(start, 'GMT', 'dd/MM/yyyy')
           var title = events[t].getTitle()
           var time = start.toTimeString().substring(0, 5) ?>
       <title><?= date+' - '+time ?></title>
       <description><?= title ?></description> 
     </item>
  <? } ?> 
</channel>
</rss>

这是URL调用的doGet()脚本:

This is the doGet() script the URL calls:

function doGet() {
  return ContentService.createTextOutput(HtmlService.createTemplateFromFile("rss").evaluate().getContent())
          .setMimeType(ContentService.MimeType.RSS);
}

但是每当我通过feedburner或任何其他RSS阅读器时,它都会产生相同的响应:

But whenever I pass it through feedburner or any other RSS Reader it comes up with the same response:

URL似乎没有引用有效的XML文件.我们遇到 出现以下问题:921行错误:元素类型元"必须 被匹配的结束标记"

The URL does not appear to reference a valid XML file. We encountered the following problem: Error on line 921: The element type "meta" must be terminated by the matching end-tag ""

即使该调用在正常的浏览器窗口中作为RSS feed加载正常,也是如此.

Even though the call loads fine in a normal browser window as a RSS feed.

我也很讨厌使用XKCD供稿的GAS RSS示例(可在此处),我的反应也一样.

I have also the tired the GAS RSS example using the XKCD feed (found here) and I am getting same response.

关于我在做什么的任何想法,我已经将Web应用程序权限设置为以我本人和任何人执行,甚至是匿名".如示例中所述.也尝试过其他没有运气的组合.

Any thoughts on what I am doing wrong I have set the web app permissions to Execute as me and Anyone, even anonymous. As said the in the example. Have tried other combinations with no luck as well.

谢谢

推荐答案

据我所知,问题是这样的:

The problem, as far as I can tell is this:

出于安全原因,内容服务返回的内容不是从script.google.com提供的,而是重定向到script.googleusercontent.com上的一次性URL.这意味着,如果您使用内容服务将数据返回到另一个应用程序,则必须确保将HTTP客户端配置为遵循重定向.该脚本可在浏览器(Firefox,Opera等)上运行,但没有RSS阅读器可以识别它.因此,在那里,不确定如何解决问题,但是您已经走了一半.

The script works on browsers (Firefox, Opera, etc), but no RSS reader recognises it. So, there, not sure how to get around it, but you're half way there.

这篇关于Google Apps脚本RSS输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆