I'm trying to track tweets via Twitter Streams API using NodeJS , but I'm facing this problem :
undefined:1
SyntaxError: Unexpected token <
at Object.parse (native)
at IncomingMessage.<anonymous> (C:\Users\ADiL-\Desktop\nodejs\twitter\tweets.js:1
7:20)
This is my code :
var https = require("https");
var option={
host : "stream.twitter.com",
path : "/1.1/statuses/filter.json?track=bieber",
method : "GET",
headers : {
"Authorization" : "Basic "+ new Buffer("username:password").toString("base64")
}
};
var request = https.request(option,function(response){
var body = '';
response.on("data", function(chunk){
body += chunk;
var tweet = JSON.parse(body);
console.log("Tweet : " + tweet.text);
});
response.on("end", function(){
console.log("disconnected");
});
response.on("error", function(){
console.log("error occured");
});
});
request.end();
and when I delete the parse and show only the chunk it give that error :
<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\
n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/filter.json?track=bieber'. Reason:
<pre> Unauthorized</pre>
</body>
</html>