Search code examples
node.jstwitter

Is that possible to retrieve tweet's from more then one specific account via Twitter API?


I know that i can get tweet from specific account with the help of "From:User" but i want to retrieve tweet's from more then one account how can i archive that in node.js ?

i've tried the Boolean search operators and the "separated by comma" (ex. From:User,User ) but did't got any luck...


Solution

  • You can get live tweets up to 5000 users with the stream API and the "follow" parameter : https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html

    To code in node, you can use this package : https://github.com/ttezel/twit

    Here is a full nodejs code to get tweets from @realDonaldTrump and @CNN when they tweet :

    var Twit = require('twit')
    
    var users = [
        '25073877', // @realDonaldTrump
        '759251' // @CNN
        ];
    
    var T = new Twit({
        consumer_key:         '...',
        consumer_secret:      '...',
        access_token:         '...',
        access_token_secret:  '...'
        });
    
    var stream = T.stream('statuses/filter', { follow: users }) 
    stream.on('tweet', function (tweet) {
        if(!users.includes(tweet.user.id_str)) {return;}
        console.log(tweet.user.screen_name + ': ' +  tweet.text);
        });