I am trying to use (in PHP) the twitch API to get new (un)followers notifications. I am a PHP beginner. The problem is that
gives oscillating answers. An example:
- I go to https://api.twitch.tv/kraken/channels/channelname/follows
- Someone hits the follow button.
- After a while I refresh the page – It’s OK, I can see the new follower inside the JSON.
- I refresh again and now the new follower is GONE (or maybe not, it seems random). It almost looks like it reverted to the previous state before the new follow.
- Another refresh and he/she might back (or not).
- After a while it finally stabilizes (at least it seems).
What am I doing wrong? It is annoying because the script is actually sending messages about new followers and unfollowers via IRC to channel’s twitch chat. So it looks like: X followed, X unfollowed, X followed, etc… until it stabilizes.
i can’t say for sure, so here’s a guess:
the response to that endpoint is probably cached and served from multiple servers.
the cache server that supplies data for your call could be different each time.
you probably won’t see consistent until all the caches are expired to represent the newest data
I thought it’s something like that (if it is). Any way to prevent it? (I suppose I can code in some ‘cooldown time’ for each new (un)follower in which any changes of the follow status will be ignored.) And I’ve got another question: Is there any (API or other) way to track followers list updates? (Apart from catching that from the email notifications.) How does apps like ‘TNotifier’ work?
Thank you for the help.
the one you’ve found seems like the only public endpoint
your idea seems like it would work
another one would be to look at the response headers you’re getting and compare (what you know to be) correct responses to wrong ones. Maybe there’s a date or something else you can use to identify data from an old cache.
I’m seeing the exact same behavior and I think Hephaestus is correct as well. At least that was my guess too.
What I’m doing to handle this is creating a local cache with an age. Removals are only removed after five minutes. This keeps oscillations from making my bot go crazy.
– edit –
If you want to get an idea of how I did it take a look at the Followers class in my Twacker text-to-speech chat client.