jQuery plugin to fetch tweets using the Twitter JSON API

Over a year ago I posted a script showing how you could fetch tweets using jQuery and Twitter’s JSON API, and to my surprise it has had a decent amount of traffic. So now that I’ve been learning more JavaScript and jQuery I decided to re-write the script as a jQuery plugin.

The plugin allows for much easier re-use and integration as well as adding some features like optionally showing the users profile data and autorefresh.

Once jQuery and the plugin are loaded you can load a user’s tweets as simple as:

Hope you enjoy!

Categories: Uncategorized
  • shivabeach

    Very nice.? Strangely enough, I ended up here while trying out the RSS reader you made for4 nettuts in Nov? 2009 :).? I like that app as well!

    • lupomontero

      Thanks for the feedback 😉 … I can’t?believe it’s nearly two years since the feed reader…

  • nsteen45

    This is great! I was wondering though, does this only display the last week of tweets? I’m seeing that if I set the count of tweets to be 5 and only have 3 tweets in the last week, it is only displaying the 3 for some reason.

    • lupomontero

      Thanks! The problem is that twitter’s search API will only return “recent” tweets, so sometimes the number of tweets returned from the API will be less than the value specified in the count option. I guess the “count” option can be taken as a “maximum number of tweets to fetch” 😉

  • This cool. Does this fall into the issue of the 150 limit on the request by twitter?

    • lupomontero

      The plugin issues the requests from the browser so the limitations would apply there I guess. By default the plugin refreshes tweets every 5 minutes so that should be within the limit in most cases. You can also play around with both the “refreshInterval” and “cache” options to reduce the number of times the plugin hits the twitter api.

  • Pingback: Fetching tweets with jQuery and the Twitter JSON API | Lupo Montero's Blog()

  • Hi, great script!

    One question, for some accounts I’m only getting 2 tweets and for others I’m getting 3. Exactly the same settings!

    • lupomontero

      Hi Mike,
      Bear in mind that the twitter JSON api will only return “recent” tweets. So sometimes you will get fewer tweets than the specified “count”.

      L

  • Ashutosh Kale

    Does this api support if I want to specify a search term in the tweet. For example I may want to search for tweets that contain word “United States”, for any user.

  • Thanks! I’ve been looking for this for a while now. However, with some usernames I can get that persons tweets but with others I cannot get anything, only the userinfo but no tweets, even though they definately have tweets posted. Does the person need to enable their tweets to be shared on other websites?

    • lupomontero

      @facebook-627260149:disqus Note that the twitter API will only return recent tweets, so if the twitter account doesn’t have any recent updates it will return an empty list. I hope this helps…

  • Thanks for the post!!

    But, does this really work? Will it not throw Cross Origin Resource Sharing error? I believe Twitter has not added CORS to public read-only APIs and hence the getJSON method will throw error. Please correct me if I am wrong.

    • ignore that.. i just discovered the purpose of JSONP and the callback=? 🙂 thanks again for your post!!

      • lupomontero

        😉

  • amyh

    This is great! How would a call a function after the tweets have loaded?