I am using the following code to access twitter streaming api with nodejs:
var https = require('https');
var options = {
host : 'stream.twitter.com',
path : '1.1/statuses/sample.json',
method : 'GET',
headers : {
"Authorization": "Basic "+new Buffer("username:password").toString("base64")
}
};
var request = https.request(options,function(response){
var body = '';
response.on("data",function(chunk){
console.log(chunk.toString("utf8"));
var tweet = JSON.parse(chunk);
console.log(tweet.text);
});
});
request.end();
I already tested the username and password being used. Working fine.
When I print the chunk, I get the following
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '1.1/statuses/sample.json'. Reason:
<pre> Unauthorized</pre>
</body>
</html>
Appreciate your assistance.
Regards