A Web Design Community curated by Chris Coyier

Code Snippets Gallery

Code Snippets > jQuery > Display Last Tweet Submit one!

Display Last Tweet

$.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) {
     $("#twitter").html(data[0].text);
});

Make sure you change username.json to your actual username and #twitter to the actual selector you wish to update.

12 Responses

  1. Jamie says:

    Love it!

  2. Jamie says:

    But how can I show the last several tweets?

  3. Add this
    callback=twitterCallback2&count=1
    after this callback=?

    Change the 1 to as many as you’d like.

  4. SubSONiK says:

    I tried to use the

    callback=twitterCallback2&count=1

    It doesn’t seem to work for some reason…

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

    Connecting to Twitter…

  5. Jack says:

    Yeah, similar sort of thing, can get the one on it’s own to work, but no more than that…

  6. Josh says:

    For those having an issue with more than one item, it’s because you have to put it inside of an array if it’s more than one item.

    Something like:
    instead of:

    (data){
    
    });

    use

    (data){
     for (i = 0; i < item.length; i++) {
                var each = item[i];
    
     }
    }
  7. Jay says:

    Will Twitter limit the number of jSON requests my server makes? In other words, if my site gets 1000 hits per hour should i be caching the tweet in a database? Or does twitter see it as the client making the request rather than my web server?

    • This site does OK without it… but… I probably should be caching. Caching something like this is just a good practice period. Regarding the limits, I’m not sure there is on stuff like just pulling from the timeline. I think it’s stuff like search that is limited. Could be wrong though.

  8. Ryan says:

    you can also refer to this site on how to display your latest tweets in twitter. with twitter API.

    http://www.ryscript.co.cc/web/how-to-display-latest-tweets-using-javascript-and-twitter-api/

    thanks..

  9. what if i dont want to get tweets from twitter i want to show it from my own mysql database any suggestions ?

  10. Nice simple code..
    I gonna use that one..
    Thanks

Leave a Comment

Remember:
  • Be nice.
  • Wrap multiline code in <pre> and <code> tags and escape it first (turn <'s into &lt;'s).
  • You may use regular HTML stuff like <a href="">, <em>, and <strong>
* This website may or may not contain any actual CSS or Tricks.