/ Published in: JavaScript
I needed to make an HTTP request with basic authorization for twitter streaming API. Users Twitter node library - https://github.com/jdub/node-twitter (npm install twitter ). I had to tweak it so I could avoid the complications of using oAuth on an all server-side implementation.
Expand |
Embed | Plain Text
//Create a client (need to pass it these values??) var client = http.createClient(80, 'stream.twitter.com'); //Request with headers for basic auth, which Twitter also accepts in addition to oAuth //Note that we're using method 'statuses/filter' and parameter 'track' //@Link http://dev.twitter.com/pages/streaming_api_methods#statuses-filter var request = client.request("GET", '/1/statuses/filter.json?track=some_keyword',{ "Host":"stream.twitter.com", "Authorization":"Basic " + new Buffer('username' + ":" + 'password').toString('base64'), //Need to create buffer object and base64 encode it "User-Agent": "Twitter-Node" }); request.on('response', function(response) { response.on('data', function(chunk) { console.log(chunk); //should be object with tweet information }); response.on('error', function(error) { console.log(error); }); response.on('end', function () { console.log('request end'); }); }); request.on('error', function(error) { console.log(error); }); request.end();
You need to login to post a comment.
