Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (66 sloc) 2.325 kB
<!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>
Jump to Line
Something went wrong with that request. Please try again.