Hi all,
I have been trying to pull some viewership and follower data from the API using Python. I generally make a page requests for a games page for the top channels. For example, the top 5 channels for LoL:
url = 'https://api.twitch.tv/kraken/streams?limit=5&offset=0&game=League+of+Legends&broadcaster_language=&on_site=1'
data = requests.get(url)
data = data.json()
for channel in data['streams']:
print(channel)
Now, this returns all the data for the top five channels. I, however, find that if i want to iterate through the followers of all these channels I sometimes get returned key errors. For example
for channel in data['streams']:
print(channel['channel']['followers'])
This returns followers for most of the channels, and then once in a while (differs per channel every time) it fails to return the followers. I have gone through the API page as well and I am not able to find the follower key in the request.
As you can see in the file in the link, the RiotGames2 channel does have followers included, but the MushIsGosu channel does not return the same API format.
I wanted to note that if I run the same code 2 seconds later it will not give a key error for MushIsGosu but likely for another channel. Sometimes it also just gives follower data for all of them, but I get an incomplete response more often.
Does anyone know what I am doing wrong or what is going on here?
Cheers,
Pieter