0
votes

I am using backbone.js, and trying to fetch some json from twitter, but it doesn't work, the collection's length is 0. Here's the code.

           
var Tweet = Backbone.Model.extend();

var Tweets = Backbone.Collection.extend({
    model: Tweet,
    url: 'http://api.twitter.com/1/favorites.json?screen_name=dhh',
    parse: function(response) {
        return response.results;
    }
});

var tweets = new Tweets();
tweets.bind('reset', function(tweets) {
   alert(tweets.length);
});
tweets.fetch();

2
but that one doesn't have anything to do with jsonAndy
but that solution doesn't work for me as well, i paste the code from the answer, and it doesn't work. I updated the code by using the advice from the other question, but this time it doesn't even trigger alert.Andy
My linked example works for me: jsfiddle.net/edwardmsmith/pKVFX/1 Perhaps the favorites API call is more picky about origins - Your code throws an origin not allowed error from twitter when run on jsFiddle and also from file://. Are you running it from the filesystem? Or localhost? Or from a real server? Are you getting an ajax error. Supernova's answer blow is correct as well - the response is just an arrayEdward M Smith

2 Answers

1
votes

try

parse: function(response) {
  return response;
}

pointing my browser to api.twitter.com/1/favorites.json?screen_name=dhh i don't see a .results property, just an array with objects

0
votes

The solution is to get rid of the parse function, which has the same effect as the other answer suggests, and add &callback=?