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

ぃ、小莉子 提交于 2020-01-07 05:31:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!