问题
I cannot able to monitor the twitter.I followed the procedure to do the sentiment analysis (twitter) in node.js code.It verified my twitter account correctly.but it shows stream is not a function. I enclosed the code .can anyone solve this issue.Thanks in advance...
app.get('/watchTwitter', function (req, res) {
const twitter = new twitterAPI({
consumerKey: "asas",
consumerSecret: "sdcscs"
});
const accessToken = "cdccd";
const accessTokenSecret = "csdcs";
var stream;
var testTweetCount = 0;
var phrase = 'bieber';
twitter.verifyCredentials(accessToken, accessTokenSecret, params, function (error, data, response) {
if (error) {
console.log(error);
} else {
console.log(data["screen_name"]);
stream = twitter.stream('statuses/filter',
{
'track': phrase
}, function (stream) {
res.send("Monitoring Twitter for \'" + phrase + "\'... Logging Twitter traffic.");
stream.on('data', function (data)
{
testTweetCount++;
if (testTweetCount % 50 === 0)
{
console.log("Tweet #" + testTweetCount + ": " + data.text);
}
});
});
}
});
});
app.listen(8086,function()
{
console.log("port is listen on 8086");
});
回答1:
You are referring Twitter npm package, but you are using node-twitter-api. See the documentations. For statuses
, you need to use following method.
twitter.statuses("update", {
status: "Hello world!"
},
accessToken,
accessTokenSecret,
function(error, data, response) {
if (error) {
console.log(error);
} else {
console.log(data);
}
}
);
来源:https://stackoverflow.com/questions/47263815/twitter-stream-is-not-a-function-in-node-js