Search code examples
node.jstwitterstreamnodestwitter-streaming-api

How to implement direct message stream using Twitter API in node js?


I have tried Twitter documentation but it does not specify its' implementation. I have used package 'twitter' for streaming. On that package's documentation page: this doc they have provided only status/filter stream. I need direct message stream in my node js application. I hasn't found any example for this on internet. Can anyone provide example for how to implement direct message stream using Twitter API in node js with code? Any help would be appreciated.


Solution

  • After searching through and trying many node package finally i got my answer using twit package. I have created direct message stream using twit package like shown in code below.

    var Twit = require('twit')
    var T = new Twit({
        consumer_key:         '...',
        consumer_secret:      '...',
        access_token:         '...',
        access_token_secret:  '...'
    })
    var stream = T.stream('user');
    stream.on('direct_message', function (eventMsg) {
        console.log(eventMsg)
    })
    

    This stream will return json data of direct message every time message come to authenticating user.