Search code examples
node.jstwitter

nodejs twitter api get tweets by multiple public account or screen_names


I am trying to get tweets by multiple public account say @TwitterDev and @tolga_tezel.

Using node.js and twit package for this purpose.

T = new Twit({
    consumer_key: TWITTER_CONSUMER_KEY,
    consumer_secret: TWITTER_CONSUMER_SECRET,
    access_token: TWITTER_ACCESS_TOKEN,
    access_token_secret: TWITTER_ACCESS_TOKEN_SECRET,
});

getTweets = async (request:Request, reponse:Response)=>{
    //const {keyword} = request.params;       
    const data = await this.T.get('statuses/user_timeline', { screen_name:'twitterdev', count: 10 });
    reponse.send(data);
}

Something like :

const data = await this.T.get('statuses/user_timeline', { screen_name:'twitterdev', screen_name:'tolga_tezel', count: 10 });

How can it be done? Can it be done in a single api call?


Solution

  • It is not possible to do this in a single API call. The statuses/user_timeline API only takes a single username (screen_name) as a parameter (see the Twitter documentation). To achieve this you will need to make multiple calls to the user_timeline API, with an individual username each time.