How to get tweets from the users in node.js

倾然丶 夕夏残阳落幕 提交于 2019-12-12 00:06:27

问题


I am making a small application build on node.js, which needs real time tweets from the users twitter account. I have used for that "Twit" ( node.js library, look at this ) and write following code at server side.

var Twit = require('twit');

var T = new Twit({
  consumer_key:         '...',
  consumer_secret:      '...',
  access_token:         '...',
  access_token_secret:  '...',
  timeout_ms:           60*1000,  // optional HTTP request timeout to apply to all requests.
});

var userids = '100001,100002,100003';
T.stream('statuses/filter', 
    {
        follow: userids,
        stall_warnings: true
    },
    function(stream) {
        stream.on('tweet', function (tweet) {
            console.log(tweet);
        });
    }
);

I have to use stream because I need real time tweets of the users (100001,100002 and 100003). I have seen many example, shows me same code. But in my case it is not working. If I pass single userid (e.g. 100001), it works sometime, sometime not. Don't know what is the problem with this code. Can anybody help me solve it out.

Thanks.

来源:https://stackoverflow.com/questions/37965221/how-to-get-tweets-from-the-users-in-node-js

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