Skip to content

Instantly share code, notes, and snippets.

@eldondev
Created October 22, 2010 05:07
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 eldondev/639972 to your computer and use it in GitHub Desktop.
Save eldondev/639972 to your computer and use it in GitHub Desktop.
A super-simple example of using the jsonp callback functionality of twitter search to slap tweets in a div.
<html>
<head>
<script type="text/javascript">
function showTweets(tweets) {
var newhtml = "";
for(var a = 0; a < tweets.results.length; a++) {
tweet = tweets.results[a];
newhtml += "<img src='" + tweet.profile_image_url +"'>" + tweet.text + "<br>";
}
document.getElementById("tweetdiv").innerHTML = newhtml;
}
var foo = function(query) {
var tweet = document.createElement('script');
tweet.type = 'text/javascript';
tweet.async = true;
tweet.src = 'http://search.twitter.com/search.json?q='+ escape(query) +'&callback=showTweets&rpp=10';
var scripts = document.getElementsByTagName('script')[0];
scripts.parentNode.insertBefore(tweet, scripts);
};
foo("#dc404");
</script>
</head>
<body>
<div id="tweetdiv"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment