1

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 !

Vukašin Manojlović
  • 2,645
  • 2
  • 21
  • 26
Cristina Ursu
  • 201
  • 2
  • 6
  • 18
  • 1
    the current app in the windows store uses this api : http://infinigag.com/api/ its json so its much easier to work with. – cillierscharl Nov 21 '12 at 20:27
  • ok, I know but I don't want to change this function , I need to keep it and adapt it. And I don't understand why it isn't working – Cristina Ursu Nov 21 '12 at 20:35
  • 1
    It's not working because the rss feed references a css file `http://feeds.feedburner.com/~d/styles/itemcontent.css` which the app doesnt allow downloading this content. – cillierscharl Nov 21 '12 at 20:36
  • 1
    http://stackoverflow.com/questions/12855407/cant-get-feed-in-windows-8-app here is someone with the same issue. – cillierscharl Nov 21 '12 at 20:37
  • I have found that post but it is not the same problem. Changing the link to http://9gag.com/?feed=rss doesn't work – Cristina Ursu Nov 21 '12 at 20:39
  • because that url doesnt output an rss feed <_< its the normal page. You will need a way to strip out the css references in that feed otherwise it wont work. – cillierscharl Nov 21 '12 at 20:41

2 Answers2

1

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);
    }
});
cillierscharl
  • 7,043
  • 3
  • 29
  • 47
  • Thanx, but it doesn't work. I get SCRIPT16388: Exception is about to be caught by JavaScript library code at line 9428, column 9 in ms-appx://microsoft.winjs.1.0/js/base.js 0x80004004 - JavaScript runtime error: Operation aborted File: base.js, Line: 9428, Column: 9 APPHOST9601: Can’t load . An app can’t load remote web content in the local context. File: default.html – Cristina Ursu Nov 21 '12 at 21:32
  • 1
    I have the application running now it works; is your win.js xhr request type set? – cillierscharl Nov 21 '12 at 21:36
  • 1
    here you go, here is my solution : https://dl.dropbox.com/u/67200967/9gag%20reader%20sample.zip I have to leave now but Ill be back in a few hours if you have more questions. – cillierscharl Nov 21 '12 at 21:48
  • Thank you very much for your solution, but I don't know if you have seen that the project has some faulty behaviours. It doesn't get all the feeds, it gets only 10 pictures. Is there any way how we can make it get all the feeds(the older ones and the new ones) or we need an asynchronous method like in c#? – Cristina Ursu Nov 21 '12 at 22:27
  • 1
    @CristinaUrsu I hope you understand that the solution was just to show you how to get it to work and not a complete application. the limit on 10 pictures is because that is all that the feed provides. If you want more you should look into using the API I mentioned from the start since you can view all pages, hot, trending, vote and go back in time too. http://infinigag.com/api/ – cillierscharl Nov 22 '12 at 06:33
1

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

Eduard7
  • 725
  • 7
  • 19