Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error when trying to use backbone.js with Facebook json feed

I have a super simple Backbone model/collection that wraps around a facebook feed.

window.Story = Backbone.Model.extend({});
window.Stories = Backbone.Collection.extend({
  model: Story,
  url: 'https://www.facebook.com/feeds/page.php?id=186424828078649&format=json&callback=?',
  parse: function(response) {
    console.log(response);
    return response.entries;
  }
});

stories = new Stories();
stories.fetch();

This results in a syntax exception in Chrome ("Unexpected token :"), or in Firefox, an invalid label "title": {.

The Chrome message is a little cryptic, but the Firefox message seems to indicate that the JSON response is being returned. the parse() function is never getting called (as far as I can tell, I've set a breakpoint and added a console.log statement and I'm not seeing anything), so is there anything else that Backbone needs to know in order to parse JSON?

My first thought was that it might be a Cross-Domain issue, but I'm using &callback=? which should make sure that $.ajax uses jsonp. I'm betting that this is working, because Firefox is identifying the 2nd line correctly as "title": {.

Any ideas?

PS, jsfiddle is at http://jsfiddle.net/KcE9L/ if you'd like to test things out.

like image 588
carpeliam Avatar asked Feb 25 '26 06:02

carpeliam


1 Answers

I figured it out after some deep debugging. It's because Facebook ignores/doesn't support JSONP, and leaves me with this problem: Jquery success function not firing using JSONP. Now I need to figure out how to get CORS working with Facebook, so if anybody can help me along those lines, I'd be curious.

like image 87
carpeliam Avatar answered Feb 27 '26 20:02

carpeliam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!