socket hang up
https を使用した基本認証で Twitter ストリーミング API に接続すると、エラーが発生します。認証時にエラーが発生していると思います。
var https = require("https");
var options = {
host: 'stream.twitter.com',
path: '/1.1/statuses/filter.json?track=bieber',
method: 'GET',
headers: {
"Authorization": "Basic " + new Buffer('UserName' + ":" + 'Password').toString("base64")
}
}; //end of options
var request = https.request(options, function(response){
var body = '';
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.on("data", function(chunk){
var tweet = JSON.parse(chunk);
console.log("Tweet " + tweet.text);
}); // end of data
response.on("end", function(){
console.log("Disconnected!!");
}); // end of end
response.on("error", function(){
console.log("error occured");
}); // end of error
}); // end of request
request.on("error",function(error){
console.log("Error: " + error.message);
}); // end of error
この URL にアクセスしようとすると、正常に動作します。
https://username:password@stream.twitter.com/1.1/statuses/filter.json?track=twitter