Skip to content

Instantly share code, notes, and snippets.

@ydn
Created March 3, 2010 00:28
Show Gist options
  • Save ydn/320156 to your computer and use it in GitHub Desktop.
Save ydn/320156 to your computer and use it in GitHub Desktop.
Fetch Twitter search results using YQL + JSONP + a simple JavaScript handler function
<!-- Fetch Twitter search results using YQL + JSONP + a simple JavaScript handler function -->
<!-- Described in blog post: http://developer.yahoo.net/blog/archives/2010/03/yql_code_samples_yql_is_easy_to_use.html -->
<ul>Puppy Tweets:</ul>
<script>
function handleResponse (json) {
var results = json.query.results.json.results,
ul = document.getElementsByTagName( 'ul' )[0],
li = null;
for ( var i = 0; i < results.length; i++ ) {
li = document.createElement( 'li' );
li.innerHTML = results[i].text;
ul.appendChild( li );
}
}
</script>
<!-- run this query in the YQL console: http://developer.yahoo.com/yql/console/?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fsearch.twitter.com%2Fsearch.json%3Fq%3Dpuppy%22 -->
<script src="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fsearch.twitter.com%2Fsearch.json%3Fq%3Dpuppy%22&format=json&diagnostics=false&callback=handleResponse"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment