twitter.stream is not a function in node.js?

2019-08-21 07:08发布

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条回答
神经病院院长
2楼-- · 2019-08-21 08:09

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); 
        }
    }
);
查看更多
登录 后发表回答