Skip to content

Instantly share code, notes, and snippets.

@phstc
Created December 29, 2010 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phstc/758666 to your computer and use it in GitHub Desktop.
Save phstc/758666 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="https://github.com/phstc/jquery-twitter/raw/master/src/jquery.twitter.js"></script>
<script>
/*
@pablocantero
http://pablocantero.com
https://github.com/phstc/jquery-twitter/
https://gist.github.com/758666
*/
(function(){
/*
Customized callback to show an error message on the tweets's lookup
This callback is optional, the default error callback shows an alert(errorMessage)
*/
var tweetsErrorCallback = function(errorMessage, tweet){
var msg = 'Oops! \
<a href="http://dev.twitter.com/pages/rate-limiting">Twitter Rate Limit Exceeded</a>. \
Try again later or search \
<a href="http://twitter.com/search?q=' + tweet.toQuery() + '">directly on Twitter</a>';
$('#tweets').html(msg);
}
/*
Customized callback to show the tweets
Remember that, this plugin is only for tweets's search, it does not generate view
*/
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
// http://www.lupomontero.com/fetching-tweets-with-jquery-and-the-twitter-json-api/
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="http://twitter.com/' + tweet.from_user + '">' + tweet.from_user + '</a></span> \
<span>' + hours + ' hours ago</span></dd></dl> \
<div>' + tweet.text + '</div> \
</li>';
}
$('#tweets').html('<ul>' + tweetsLi + '</ul>');
}
$(document).ready(function(){
/*
Here is the example of the plugin usage
*/
var tweets = Twitter.tweets();
tweets.containing('pablocantero').all(tweetsSuccessCallback, tweetsErrorCallback);
});
})();
</script>
</head>
<body>
<div id="tweets">
Loading tweets
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment