public
Last active

  • Download Gist
Twitter_in_Javascript.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/*
Javascript interface to Twitter search API.
Call it like
 
Twitter.search({q:'"is down'",
callback:function(data){
doSomethingAwesome(data)
}
})
You can also use any of the other options like lang, since_id, etc.
 
It should be framework agnostic too. Though, I like prototype.
*/
Twitter = {
_callbacks:{}
};
 
Twitter.search = function(opts){
//opts.q
//opts.since_id
//opts.rpp
//opts.lang
//opts.page
//opts.callback
var query_parts=[];
for(key in opts)
{
if(key!='callback')
query_parts.push(escape(key)+'='+escape(opts[key]));
}
var key = "c"+Date.now().toString()
Twitter._callbacks[key] = function(data){
opts.callback(data.results);
delete Twitter._callbacks[key]
}
 
query_parts.push("callback=Twitter._callbacks."+key)
 
var body = document.getElementsByTagName("body")[0];
var script = document.createElement("script");
script.src = "http://search.twitter.com/search.json?"+query_parts.join("&")
body.appendChild(script)
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.