Hi! I’m studying for an exams and my aim is to get all the ‘follows’ for a user. I’m using Python3 and the Twitch API v5.
The problem is, that I can’t manage to get more than 100. Seems that the ‘follows’ object doesn’t contain a cursor.
Is there any way/trick for doing it? Probably I’m doing something stupid, but I’m stuck!
An offset of 101 will result in missing a follower. The offset should increment by the same value as the limit, so with a limit of 100 the offset should be 0 (which is default). 100, 200 and so on. Think of the offset as the starting point, so by default you get the first 100 entries, 0 to 99, then with an offset of 100 you get entries 100 to 199.
I think i’m messing up with the code… Maybe you can help me. It goes on loop becouse on the second get call it doesn’t take 100 user, but only 85…
off=0
top_channel = [‘Ninja’] #for tests
seguiti = []
for user in top_channel:
follows_url = requests.get('https://api.twitch.tv/kraken/users/{}/follows/channels?client_id={}&offset={}&limit=100'.format(user,client_id, off))
follows_json= json.loads(follows_url.text)
for j in follows_json['follows']:
seguiti.append(j['channel']['display_name'])
while len(seguiti)< follows_json['_total']:
print('incrementa offset')
off=off+100
follows_url = requests.get('https://api.twitch.tv/kraken/users/{}/follows/channels?client_id={}&offset={}&limit=100'.format(user,client_id, off))
follows_json= json.loads(follows_url.text)
for k in follows_json['follows']:
seguiti.append(k['channel']['display_name'])