public
Last active

  • Download Gist
jquery.twitter-example.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<!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>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.