the Forum

How to use external RSS feeds for your site in jSON with jQuery.

Michael Rosario pic

Posted on November 4, 2011 by Michael Rosario
Total Posts: 32  |  Join date: 03-12-11

We had a client that needed to display twitter and Facebook feeds to their site without using PHP and just jQuery.

The obstacle occurs because I can’t really use $.GET or $.Ajax because it’s restricted to the same domain (Cross-domain Policy), unless we use PHP.

The javascript work around is to use $.getJSON(). I know for a fact that twitter and facebook have RSS feeds that I can use, but how do I convert the RSS feeds?

Thanks to Yahoo!’s API, we can easly convert RSS to XML or jSON.

Here’s my sample code to output twitter and facebook feeds:


$.YQL("select * from rss where url='[USER_HANDLE]&count=3'", function(data{
var tweet '@'+this.title;
'.feed-twitter .bdy .items').append('<li class="thumb-feature"><p>'+tweet.parseURL().parseUsername().parseHashtag()+ '</p><p>'+this.pubDate.dateConvert()+'</p></li>');

$.YQL("select * from rss where url='[USER_ID]&format=rss20' limit 3", function(fJson{
$('.feed-facebook1 .bdy .items').append('<li class="thumb-feature"><p>'+this.description+'</p><p>'+this.pubDate.dateConvert()+'</p></li>').find('a').attr("href",;
}); // END of $document.ready

String.prototype.dateConvert = function(){
var datetext this.toString();
jDate = new Date(datetext); 
HH jDate.getHours();
MM jDate.getMinutes();
AM "";
HH 11){ AM "PM"else { AM "AM"};
HH 12){ HH HH 12};
MM 10){ MM "0" MM}
var month=new Array(12);
date '' +  month[jDate.getMonth()' ' +jDate.getDate()+', ' jDate.getFullYear().toString() + " at " HH +":"MM " " AM;
String.prototype.parseURL = function(){
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function (url{
String.prototype.parseUsername = function(){
return this.replace(/[@]+[A-Za-z0-9-_]+/g, function (u{
var username u.replace("@""")
        return"" username);
String.prototype.parseHashtag = function(){
return this.replace(/[#]+[A-Za-z0-9-_]+/g, function (t) {
var tag t.replace("#""%23")
        return"" tag);
String.prototype.format = function(){
var this,
    while (
i--) {
s.replace(new RegExp('\\{' '\\}''gm'), arguments[i]);
YQL = function(querycallback{
if (!query || !callback{  throw new Error('$.YQL(): Parameters may be undefined');  }
var encodedQuery encodeURIComponent(query.toLowerCase()),
url '' encodedQuery '&format=json&callback=?';

Tags: facebook, feeds, jquery, json, parser, rss, twitter, yahoo, yql

There are no answers yet.  Add yours below.

add your comment here

or register to create an account