Skip to content
jQuery Twitter Search Plugin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


I found many jQuery Twitter Plugins, but most of them work with searching and displaying the tweets. In the project that I worked the layout to display the tweets was specific. So I couldn't use the plugins' layout.

The main idea of Twitter Search Plugin is only for tweets search. You will need to implement the layout to display the tweets.

What's the difference

The available plugins on the internet use an ugly syntax to search:

  ${from: 'pablocantero', text: 'hello+world', container: 'myDivId'});

Twitter Search Plugin is DSL based

  var tweets = new Twitter.tweets();
		alert("It’s a customized function to display the tweets");

The Twitter Search API

This Plugin follows the Twitter Search API documentation.

Twitter Search API Method: search

Implemented conditions

The actual conditions were implemented on-demand. If you want a new condition, please have a look at "Do you want to improve the jQuery Twitter Plugin?".

  • conditions([text or hashtag])
  • and([text or hashtag])
  • or([text or hashtag])
  • from([twitter username])
  • to([twitter username])
  • order([mixed, recent or popular]) - default recent
  • limit([0..100]) - default 100
  • page([page num]) - default 1
  • locale([locale]) - optional. specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases


The full example is available on

Import the JavaScript

  <script src=""></script>
  <script type="text/javascript" src#""></script>

Create success callback

This plugin is only for tweets search, it does not display the tweets. You need to implement the layout to display the tweets.

  Customized callback to show the tweets
  var tweetsSuccessCallback = function(data){
  	var tweetsLi = '';
  	for(var i = 0; i < data.results.length; i++){
  		var tweet = data.results[i];
  		// Calculate how many hours ago was the tweet posted
  		var dateTweet = new Date(tweet.created_at);
  		var dateNow   = new Date();
  		var dateDiff  = dateNow - dateTweet;
  		var hours     = Math.round(dateDiff/(1000*60*60));
  		tweetsLi += '<li> \
  		      <dl> \
  		              <dt><img src="' + tweet.profile_image_url + '" /></dt> \
  		              <dd> \
  		                      <span><a href="' + tweet.from_user + '">' + tweet.from_user + '</a></span> \
  		                      <span>' + hours + ' hours ago</span></dd></dl> \
  		      <div>' + tweet.text + '</div> \
  	$('#tweets').html('<ul>' + tweetsLi + '</ul>');

Create an error callback

Customized callback to display an error message This callback is optional, the default error callback shows an alert(errorMessage).

  var tweetsErrorCallback = function(errorMessage, tweet){
	var msg = 'Oops! \
		<a href="">Twitter Rate Limit Exceeded</a>. \
		Try again later or search \
		<a href="' + tweet.toQuery() + '">directly on Twitter</a>';

Create a search query

  var tweets = Twitter.tweets();
  tweets.containing('jquery.twitter').all(tweetsSuccessCallback, tweetsErrorCallback);

Combine OR and FROM queries

Thanks to pheze issue/2.

You can combine OR and FROM queries.

  var tweets = new Twitter.tweets();

This query above return all tweets containing 'jquery-twitter', if the result is empty it will return all tweets from @pablocantero


To execute the Test suite, just open jquery.twitter-test.html in your browser. The tests were developed with

Do you want to improve the jQuery Twitter Plugin?

You’re welcome to make your contributions and send them as a pull request or just send me a message


Thanks to pheze

You can’t perform that action at this time.