Fer
Fer

Reputation: 3

getJson + Twitter

Im not that much into programation but I've been trying to edit a base code one with another ones to display more than 1 tweet but it dosen't work, could anyone help me?

 $.getJSON("http://twitter.com/status/user_timeline/user.json?count=3&callback=?", 
  function(data) {
      $("#tweet").html(data[0].text);
  }); 

Thanks!

Upvotes: 0

Views: 1036

Answers (1)

villecoder
villecoder

Reputation: 13483

data is an array. So data[0] accesses the first tweet returned from twitter. You need to iterate over the array and append the other tweets to your div.

$.getJSON("http://twitter.com/status/user_timeline/user.json?count=3&callback=?", 
function(data) {
  $(data).each(function() {
     $("#twitter").append($(document.createElement('div'))
        .html(this.text).addClass('tweet'));
  }
}); 

Edit: Changed selector to target #twitter div and add a tweet class to each tweet.

Upvotes: 4

Related Questions