Created
November 21, 2009 04:50
-
-
Save miya2000/240009 to your computer and use it in GitHub Desktop.
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
| (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