Retrieve tweets using jQuery

Twitter Logo

As many of you out there, I’m a Twitter user too. As most of you have, I too have spent quite some time reading the Twitter API and understanding it.

I stumbled upon a forum message (in Hebrew) asking how can you retrieve your (or anybody else’s) tweets using JavaScript only and no server side.

Well, there’s a way to accomplish that and it is not that complicated at all.

Change the twitterUsername var in the code to fit your username or the username you want to retrieve, please notice I took the “text” property only but the jSON result returns many more like:

Application used, profile image, time and more.

Here’s the code, enjoy!

REXML could not parse this XML/HTML: 
   1: function getuserTweets() {
   2:     var twitterUsername = 'KensoDev';
   3:     var twitCount = 50;
   4:     $.getJSON(
   5:         'http://search.twitter.com/search.json?callback=?&rpp=' + twitCount + '&q=from:' + twitterUsername,
   6:         function(data) {
   7:             $.each(data, function(i, userTweets) {
   8:                 for (var tweet = 0; tweet < userTweets.length; tweet++) {
   9:                     if (userTweets[tweet].text !== undefined) {
  10:                         $('body').append('<p>' + userTweets[tweet].text + '</p>');
  11:                     }
  12:                 }
  13:             });
  14:         }
  15:     );
  16: }
</pre></p>
REXML could not parse this XML/HTML: 
</div>
REXML could not parse this XML/HTML: 
</div>

You can of course change the tags being created, you can change the object the tags are being appended into, you can change the code to better suit your needs that’s for sure.

If you need any help feel free to comment on this post and I will help you as much as I can.

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com