Created
March 28, 2011 13:45
-
-
Save chrishamant/890476 to your computer and use it in GitHub Desktop.
quick and dirty script to search twitter streaming api
This file contains 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
var sys= require('sys'); | |
var OAuth= require('oauth').OAuth; | |
var TwitterNode = require('twitter-node').TwitterNode; | |
var consumer_key = "-"; | |
var consume_secret = "-"; | |
var access_token = "-"; | |
var access_token_secret = "-"; | |
//var oa= new OAuth("https://api.twitter.com/oauth/request_token","https://api.twitter.com/oauth/access_token", consumer_key, consume_secret, "1.0A", "http://localhost:3000/oauth/callback", "HMAC-SHA1"); | |
//dump method | |
/*oa.get("http://api.twitter.com/1/statuses/retweeted_by_me.json", access_token, access_token_secret, function(error, data) { | |
console.log(sys.inspect(data)); | |
});*/ | |
//streaming API | |
/*var body = "track=basketball,football,baseball,footy,soccer" | |
var request= oa.post("http://stream.twitter.com/statuses/filter.json", consumer_key, consume_secret,body,"application/x-www-form-urlencoded" ); | |
request.addListener('response', function (response) { | |
response.setEncoding('utf8'); | |
response.addListener('data', function (chunk) { | |
console.log(chunk); | |
}); | |
response.addListener('end', function () { | |
console.log('--- END ---') | |
}); | |
}); | |
request.end();*/ | |
// twitter-node does not modify GLOBAL, that's so rude | |
// you can pass args to create() or set them on the TwitterNode instance | |
var twit = new TwitterNode({ | |
user: '-', | |
password: '-', | |
// host: 'my_proxy.my_company.com', // proxy server name or ip addr | |
// port: 8080, // proxy port! | |
track: ["libya"], // sports! | |
// follow: [12345, 67890], // follow these random users | |
//locations: [-122.75, 36.8, -121.75, 37.8] // tweets in SF | |
}); | |
// Make sure you listen for errors, otherwise | |
// they are thrown | |
twit.addListener('error', function(error) { | |
console.log(error.message); | |
}); | |
twit | |
.addListener('tweet', function(tweet) { | |
sys.puts("@" + tweet.user.screen_name + ": " + tweet.text); | |
}) | |
.addListener('limit', function(limit) { | |
sys.puts("LIMIT: " + sys.inspect(limit)); | |
}) | |
.addListener('delete', function(del) { | |
sys.puts("DELETE: " + sys.inspect(del)); | |
}) | |
.addListener('end', function(resp) { | |
sys.puts("wave goodbye... " + resp.statusCode); | |
}) | |
.stream(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment