954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

jQuery twitter feed

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

jrock2004
Light Poster
35 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

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

scrappedcola
Posting Whiz in Training
227 posts since Dec 2009
Reputation Points: 27
Solved Threads: 45
 

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();
    });
});
JJenZz
Newbie Poster
6 posts since Jul 2010
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: