Question

I am creating a 9GAG reader app for Windows 8 by using RSS Feeds and WinJS.

Code:

function downloadBlogFeed() {
    WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" }).then(function (rss) {
        var items = rss.responseXML.querySelectorAll("item");

        for (var n = 0; n < items.length; n++) {
            var article = {};
            article.title = items[n].querySelector("title").textContent;
            var thumbs = items[n].querySelectorAll("thumbnail");
            if (thumbs.length > 1) {
                article.thumbnail = thumbs[1].attributes.getNamedItem("url").textContent;
                article.content = items[n].textContent;
                articlesList.push(article);
            }
        }
    });
}

Problem is that I can't get 9GAG Feeds from FeedBurner. I get this error:

Can't load http://feeds.feedburner.com/~d/styles/itemcontent.css. An app can’t load remote web content in the local context.

I have also tried changing

WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG" })

with

WinJS.xhr({ url: "http://9gag.com/?feed=rss" })

but I get this error:

Exception is about to be caught by JavaScript library code at line 50, column 13 in ms-appx://7df7a30e-2f19-4f36-b368-c456fde8aabd/js/default.js
0x800a138f - JavaScript runtime error: Unable to get property 'querySelectorAll' of undefined or null reference
File: default.js

and it points to this line:

var items = rss.responseXML.querySelectorAll("item");

Can you please help me, make it right?

Thank you !

Was it helpful?

Solution

Here you go:

Unfortunately there is some hacking to get the image but alas it works, such is life with a 3rd party RSS feed.

WinJS.xhr({ url: "http://feeds.feedburner.com/9GAG", responseType: 'responseXML' }).then(function (rss) {
    var items = rss.responseXML.querySelectorAll("item");

    for (var n = 0; n < items.length; n++) {
        var article = {};
        article.title = items[n].querySelector("title").textContent;
        var imageStart = items[n].textContent.indexOf('<img src="') + 11;
        var imageEnd = items[n].textContent.indexOf('"', imageStart);

        article.thumbnail = items[n].textContent.substring(imageStart, imageEnd);
        article.content = items[n].textContent;
        articlesList.push(article);
    }
});

OTHER TIPS

9GAG RSS feed is dead now, try to use a mirror like http://9gagrss.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top