Created
October 22, 2010 05:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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