Skip to content
Advertisement

How to get retrieve twitter user id from twitter handle using the twitter v2 API

I am currently using the twitter v2 API, using the following npm package link

const tweets = await client.v2.userTimeline(userId, { exclude: 'replies' });

I require the userID and not the twitter handle for this command.

How would I be able to get the twitter user id from the twitter handle using the twitter API?

Advertisement

Answer

You would use client.v2.userByUsername('handle'); and get the ID value from the response.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement