Skip to content

Instantly share code, notes, and snippets.

@brianyang
Created September 12, 2011 14:51
Show Gist options
  • Save brianyang/1211453 to your computer and use it in GitHub Desktop.
Save brianyang/1211453 to your computer and use it in GitHub Desktop.
Twitter Stream - Front End
jQuery(function(){
// Execute this code when the page is ready to work
// Create a Script Tag
var script=document.createElement('script');
script.type='text/javascript';
script.src= "http://search.twitter.com/search.json?&q=%23Ogilvy&callback=processTheseTweets&_="+ new Date().getTime();
// Add the Script to the Body element, which will in turn load the script and run it.
$("body").append(script);
});
$('body').prepend('<div id= tweet_stream />');
function processTheseTweets(jsonData){
var shtml = '';
var results = jsonData.results;
if(results){
// if there are results (it should be an array), loop through it with a jQuery function
$.each(results, function(index,value){
shtml += "<p class='title'><span class='author'>" + value.from_user + "</span>: " +
value.text + "<span class='date'>" + value.created_at + "</span></p>";
});
// Load the HTML in the #tweet_stream div
$("#tweet_stream").html( shtml );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment