How to get username from twitch API

The reason the response in the console differs from just going to the URL, is that when you go to a URL the body of the response is rendered on the page, where as when you actually receive a request there’s much more data than just the body, and in this case res is the whole response object, so what you’re likely after is res.body, but that may vary depending on which HTTP request library you’re using.

A few things worth noting though, first, v5 is a deprecated API, so don’t rely on that URL being around forever as it will be removed in the near future.

Secondly, the API uses caching, so you shouldn’t poll the same endpoint more than once a minute, which means there’s a potential for multiple new follows in that space of time but if you’re only getting the newest one at the time of your request all of the others may be missed. There is also potential for abuse that you should be aware of, as without any sort of caching to check if a user was a prior follower there would be nothing stopping them unfollowing and refollowing all the time to make your bot spam.

And finally, many users wont like being shouted out in chat when they follow a streamer, There is a significant portion of the Twitch community that just like to lurk quietly in chat and wont appreciate having attention forced on them. It’s still not a bad way to learn how to program and make use of the APIs and such, I just wouldn’t recommend actually using it on a channel though.