Follow to follow two (or multiple specific) accounts

nodejs

#1

Hi all,

I am working on a project where I want to follow two separate twitter accounts, and for a specific function to be called when each account tweets. I have it working no problem when one account tweets but not for both of them:

I believe my issue may be here:

var stream = T.stream('statuses/filter', { follow: ( userID1 , userID2 ) });

If I have follow set to just one User it works fine, however with two it will only work with one. Furthermore, it only works with the second in the list so if its: userID1, user ID2 only userID2 will work. If itsuserID2, userID1 only userID1 will work.

Full code/logic here:

//SetUp info

var Twit = require('twit'); // NPM twit package
var config = require('./config'); // the config file to allow me access Auth Keys etc
var T = new Twit(config);//run config file
 
 //end of setup

var userID1 = 'XXXXXXXXXXX1'; //TwitterAccount1
var userID2 = 'XXXXXXXXXXX2'; //TwitterAccount2


//these two lines set up the twitter API
var stream = T.stream('statuses/filter', { follow: ( userID1 ,  userID2 ) });  // here seems to be my issue?
stream.on('tweet', function (tweet) {


if (tweet.user.id == userID1 ) { // is tweet.user.id matches UserID1

  DoStuff_1(); //call this function

}  else if  (tweet.user.id == userID2 ) { // if tweet.user.id matches UserID2
 
DoStuff_2(); // call this function instead

}
  
 });
   
//Function for userID1
function DoStuff_1(){
console.log("Doing Stuff 1");
}

//Function for userID2
function DoStuff_2(){
console.log("Doing Stuff 2");

}

Any suggestions greatly appreciated!


#2

OK…I think I have a fix

//SetUp info

var Twit = require('twit'); // NPM twit package
var config = require('./config'); // the config file to allow me access Auth Keys etc
var T = new Twit(config);//run config file
 
 //end of setup

var userID1 = 'XXXXXXXXXXX1'; //TwitterAccount1

//these two lines set up the twitter API
var stream = T.stream('statuses/filter', { follow: ( userID1  ) });  // here seems to be my issue?
stream.on('tweet', function (tweet) {


if (tweet.user.id == userID1 ) { // is tweet.user.id matches UserID1

  DoStuff_1(); //call this function

}  
  
 });
   

var userID2 = 'XXXXXXXXXXX2'; //TwitterAccount2

//Separate stream for UserID2

var stream = T.stream('statuses/filter', { follow: ( userID2  ) });  // here seems to be my issue?
stream.on('tweet', function (tweet) {

if  (tweet.user.id == userID2 ) { // if tweet.user.id matches UserID2
 
DoStuff_2(); // call this function instead

}

 });

//Function for userID1
function DoStuff_1(){
console.log("Doing Stuff 1");
}

//Function for userID2
function DoStuff_2(){
console.log("Doing Stuff 2");

}

This seems to be working : )