Skip to content

Instantly share code, notes, and snippets.

@johnbhartley
Created February 7, 2013 17:29
Show Gist options
  • Save johnbhartley/4732592 to your computer and use it in GitHub Desktop.
Save johnbhartley/4732592 to your computer and use it in GitHub Desktop.
The script used to grab Twitter JSON from the API and output into list items. Also includes a sexy loading gif.
var twitter_api_url = 'http://search.twitter.com/search.json';
var twitter_user = 'onebeatchannel';
$.ajaxSetup({
cache: true
});
$.getJSON(
twitter_api_url + '?callback=?&rpp=3&q=from:' + twitter_user,
function(data) {
$.each(data.results, function(i, tweet) {
if(tweet.text !== undefined) {
var date_tweet = new Date(tweet.created_at);
var date_now = new Date();
var date_diff = date_now - date_tweet;
var hours = Math.round(date_diff/(1000*60*60));
var tweet_html = '<li>';
tweet_html += tweet.text;
tweet_html += '<div class="tweet_hours">';
tweet_html += '<a href="http://www.twitter.com/';
tweet_html += twitter_user + '/status/' + tweet.id + '">' + hours;
tweet_html += ' hours ago<\/a><\/li>';
$('#tweet_container').append(tweet_html);
}
$('#loadingmessage').hide(); // hide the loading message
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment