Google Apps Script RSS Output

萝らか妹 提交于 2019-12-21 22:02:00

问题


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.

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>

This is the doGet() script the URL calls:

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

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

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 ""

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

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

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.

Thanks


回答1:


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

For security reasons, content returned by the Content service isn't served from script.google.com, but instead redirected to a one-time URL at script.googleusercontent.com. This means that if you use the Content service to return data to another application, you must ensure that the HTTP client is configured to follow redirects.1

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.



来源:https://stackoverflow.com/questions/28326684/google-apps-script-rss-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!