Created
November 17, 2011 23:18
-
-
Save netshade/1374899 to your computer and use it in GitHub Desktop.
JSONP Twitter Search
This file contains hidden or 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 showStories(the_object){ | |
var titles = []; | |
for(var i = 0; i < the_object.results.length; i++){ // the object coming back from twitter is an object that contains the results in a member named results | |
titles.push("<li>" + the_object.results[i].text + ": " + the_object.results[i].from_user_name + "</li>"); | |
} | |
document.getElementById("story_list").innerHTML = titles.join("\n"); | |
} | |
</script> | |
</head> | |
<body> | |
<ul id="story_list"> | |
</ul> | |
<script type="text/javascript" | |
src="http://search.twitter.com/search.json?q=skyrimstories&callback=showStories"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that I defined the function in the document /head/ to ensure that the method is available for the entire page, while I kept the Twitter script load at the foot of the body. I did that just to ensure that our function doesn't get called until the rest of the page has rendered and is available to access ( namely, the ul#story_list element ).