jQuery, AJAX, and the Twitter Search API
I was perusing the Web looking for some quick and dirty Javascript I could use with the Twitter Search API to display a list of recent tweets containing a particular keyword. I came across the monitter.com widget, which was almost exactly what I had in mind, except that it includes some really great, rich features that were well beyond what I needed. I adapted and simplified the monitter script to:
linkify()
function.<b>
, and fix other XHTML validation issues, e.g. using self-closing img
tag.class
.Just like monitter, TwitStream utilizes the jQuery framework. Because jQuery is awesome.
What's New in v1.2
One bug was fixed in this version:
alt
attribute was added to each user's profile image.What's New in v1.1
Five most recent tweets mentioning #ftw:
Download the latest version of TwitStream as a ZIP file, including jquery.min and a sample HTML file.
Add the following to the head
of your site.
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="twitStream.js"></script>
<link rel="stylesheet" href="twit-stream.css" />
New in v1.1
Optionally, include "Reply", "View Tweet", and "RT" links on each tweet by setting the showTweetLinks
variable. Values you may use are reply
, view
, rt
, all
, or none
(default is none
). You may use a comma-seperated list of values, such as 'reply,view'
.
<script type="text/javascript">
showTweetLinks='all';
</script>
Add the following in the body
of your site where you'd like your tweets to appear, where foo is the keyword or hashtag you wish to search for. Twitter search operators can be used, e.g. title="#hashtag"
, title="@foo"
, title="oh AND my AND god"
, title="oh OR my OR god"
, etc. To search for an exact match, use "
around the phrase, e.g. title=""oh my god""
.
Optionally, you may change the number of results to display.
<div class="twitStream 5" id="tweets" title="foo"></div>
To create multiple instances, simply add another div
with a different id
and title
.
<div class="twitStream 5" id="tweets2" title="bar"></div>
Feel free to e-mail me at noah [at] iamnoahcooper [dot] com or follow me at twitter.com/noah_cooper.
Report any bugs at code.google.com/p/twitstream.