Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created November 21, 2009 04:50
Show Gist options
  • Select an option

  • Save miya2000/240009 to your computer and use it in GitHub Desktop.

Select an option

Save miya2000/240009 to your computer and use it in GitHub Desktop.
(function(){
var user = 'miya2000', password = '?????????';
var follows = '6489432'; // csv
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://stream.twitter.com/1/statuses/filter.json', true, user, password);
xhr.setRequestHeader('Content-Type' , 'application/x-www-form-urlencoded');
xhr.onreadystatechange = onReadyStateChange;
xhr.send('follow=' + follows);
function onReadyStateChange() {
if (xhr.readyState == 3) {
if (xhr.status != 200) {
throw new Error('status:[' + xhr.status + '] statusText:[' + xhr.statusText + ']');
}
startObserve();
}
}
function startObserve() {
var i = 0;
var preText;
var tid = setInterval(function() {
if (preText != xhr.responseText) {
var tweets = xhr.responseText.replace(/\s+$/, '').split('\n');
opera.postError(tweets[tweets.length-1]);
preText = xhr.responseText;
}
if (++i > 60) { // 1 minute.
opera.postError('over');
xhr.abort();
clearInterval(tid);
}
}, 1000);
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment