3

I'm trying to load a facebook wall feed with jQuery on the client side of my website. The feed I'm using for the facebook request is:

http://www.facebook.com/feeds/page.php?format=json&id=40796308305

I've tried the following aproaches:

1.

$.getJSON('http://www.facebook.com/feeds/page.php?format=json&id=40796308305',function(data){
   console.log(data)

});

Which returns the error:

XMLHttpRequest cannot load http://www.facebook.com/feeds/page.php?format=json&id=40796308305. Origin http://xxxx.local is not allowed by Access-Control-Allow-Origin.

2.

$.ajax({
    url: 'http://www.facebook.com/feeds/page.php',
    type: 'GET',
    dataType: 'json',
    data: {
        id: '40796308305',
        format: 'json'
    },
    success: function(data, textStatus, xhr) {
        console.log(data);
    }
});

Returns the same error.

3.

$.ajax({
    url: 'http://www.facebook.com/feeds/page.php',
    type: 'GET',
    dataType: 'json',
    data: {
        id: '40796308305',
        format: 'jsonp'
    },
    success: function(data, textStatus, xhr) {
        console.log(data);
    }

});

Returns:

Uncaught SyntaxError: Unexpected token :

And seems to be parsing the feed.

How do I load the facebook json feed so that I can access it as i do an array?

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
5442224
  • 73
  • 6

3 Answers3

1

You cannot do this with client-side only due to cross-domain policy restrictions.

You likely will need to create own proxy for that data (this endpoint for page data doesn't support JSONP and will not work with callback parameter)

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
0

Change datatype from json to jsonp, since its a cross-domain call

Johan
  • 35,120
  • 54
  • 178
  • 293
0

I see this thread is almost 6 months old so hopefully it's not too late.

function fbInfo(user, id) {
    var jurl = "https://graph.facebook.com/"+user+"&callback=?";
    console.log(jurl);
    $.getJSON(jurl, function(data) {
           //do stuff
});
}

I call the function in my html page and pass the username ("user") of the facebook page into the url variable "jurl"

Use the $.getJSON method, then manipulate the data at will.

This definitely works because I'm currently using it to pull business info from a facebook page into my website.

Spartacus
  • 1,468
  • 2
  • 15
  • 29