A few days ago, itmeJP mentioned something to the effect of “it would be cool if you could see the percentage of people in chat who are following you.” After about a day of deliberation/procrastination, I started working on such an app. In short, this app was written in Java using Spring (currently neck-deep in Spring at work, so I can belt out a simple application almost as fast as I used to be able to with Django). You can find the source code of the project here.
- Java JDK 1.7
- Eclipse Mars! I had no idea that a new version of Eclipse was out
- Maven 3
- Spring 4.1
- ActiveMQ 5.7
- h2 Database 1.4
- Unirest 1.4
Approach #1: Fetch all followers
The first attempt at this application fetched all followers of a particular streamer and stored these names in an embedded database. This worked perfectly for some streamers (like my old account with 4 followers?!) but intermittently for others. After some more error handling was added, I discovered that Twitch was sending me a 403 (Forbidden) response after 16 pages of results… what? Turns out that there is an undocumented feature that limits the follower API to only allow the retrieval of 3200 (first 1600 and most recent 1600) followers. This brings me to approach #2:
Approach #2: Fetch one at a time
Mercifully, Twitch also provides an API for one-off “does x follow y?” queries. The code written in part 1 was rewritten to instead store the replies from these one-off calls. Fortunately, I read this before attempting to implement the simple IRC member list reader. Unfortunately, I didn’t read this part before implementing the member list reader. Long story short, this solution works for smaller channels (<1000 viewers), but not for larger ones (unless of course you want to know if anyone on the moderator staff doesn’t follow you). Attempt 3 (after a two day break):
Approach #3: Use the API, stupid
Turns out that there is a tmi API that provides a viewer list (and is much, much cleaner than reading the response from NAMES). Once that API call was squared away, I spent the next few hours implementing websocket support and improving the look of the page. There isn’t much to say about this approach since it more or less ‘just worked’, which is good for my stress levels but makes for poor storytelling.
tl;dr: After getting around some weird Twitch API limitations, the app works relatively* flawlessly. Get version 0.1 of it here.