Ok so I am trying to setup on my site to have 6 of my recent tweets. I am trying to use the .getJSON method and it is just not working.

$.getJSON("http://api.twitter.com/1/statuses/user_timeline/jrock2004.json", function(data) {
        $.each(data, function(){
            $('<div></div>')
                .hide()
                .append('<span>' + this.text + '</span>')
                .appendTo('#tweets')
                .fadeIn();                             
        });
    });

Any ideas? I thought maybe it might be easier to try xml as well but I have not tried that. Thanks

Recommended Answers

All 2 Replies

Try running the above and check out the json request in firebug's net tab. Is the request going out? Does it get errors? Firebug will show you what the headers look like, what your status code is and what is being returned (as well as params sent if applicable). Your status should return as a 200 (pieces on the page such as static images and javascript will usually return 304 after the page has loaded at least once). Here is a link to twitter api documentation on status codes and what they mean to twitter apps: http://dev.twitter.com/pages/responses_errors

You need to add a callback to the URL to make it a JSONP request because you cannot do cross domain JSON requests.

So to fix your code, it's as easy as adding '?callback=?' to the end of your URL.

$.getJSON("http://api.twitter.com/1/statuses/user_timeline/jrock2004.json?callback=?", function(data) {
    $.each(data, function(){
        $('<div></div>')
            .hide()
            .append('<span>' + this.text + '</span>')
            .appendTo('#tweets')
            .fadeIn();
    });
});
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.