skip to Main Content

I am trying to use the Twitter api to listen for tweets from one user (1234)

twitterClient.stream('statuses/filter', { follow: 1234 }, (stream) => {
    stream.on('data', tweet => {
      console.log('tweet', tweet)
    })

    stream.on('error', error => {
      console.log('error', error)
    })
  })

This is a node wrapper for Twitter, node-twitter or just ‘twitter’ on npm.

The developer documentation for this feature is here: https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html

My issue is the console.log('tweet', tweet) line never fires, even when I tweet or reply. However, if I use { filter: 'MyKeywordHere' } as the second parameter, it does fire. So why can’t I follow my account activity?

3

Answers


  1. This code works!
    Package: twit

    var Twit = require('twit')
    
    
    var TW = 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 TWId = '#####'; // string
    
    var stream = TW.stream('statuses/filter', {
      follow: TWId
    });
    
    console.log('Waiting for tweets, Id:  ' + TWId);
    
    stream.on('tweet', function (tweet) {
      console.log(tweet);
    });
    

    This code also works!
    Package: twitter

    var Twit = require('twitter')
    
    
    var TW = new Twit({
      consumer_key: '#####',
      consumer_secret: '#####',
      access_token_key: '#####-#####',
      access_token_secret: '#####',
    });
    
    var TWId = '#####'; // string
    
    var stream = TW.stream('statuses/filter', {
      follow: TWId
    });
    
    console.log('Waiting for tweets, Id:  ' + TWId);
    
    stream.on('data', function (tweet) {
      console.log(tweet);
    });
    
    stream.on('error', function (error) {
      console.log(error);
    });
    
    Login or Signup to reply.
  2. The follow value must be a string

    { follow: 1234 }
    

    becomes:

    { follow: '1234' }
    
    Login or Signup to reply.
  3. I think this is because there is no user with 1234 as user_id.

    My issue is the console.log(‘tweet’, tweet) line never fires, even
    when I tweet or reply.

    Make sure that you are trying with your own user_id as follow parameter.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search