Hi, i’m trying to fetch all the viewers of the most viewed game, but it takes long time to perform all the requests, and when are finished, the number of viewers isn’t correct, it’s about the half of the correct number. I’m using Dart.
This is the code:
// id = most watched game broadcast_id
final url = ‘https://api.twitch.tv/helix/streams?game_id=$id’;
Response response;
try {
response = await dio.get(url);
} catch (e) {
print('${e.toString()} tot viewers');
}
String cursor = response.data['pagination']['cursor'];
int total = 0;
while (cursor != null) {
final newUrl =
'https://api.twitch.tv/helix/streams?game_id=$id&after=$cursor';
final resp = await dio.get(newUrl);
for (int i = 0; i < resp.data['data'].length; i++) {
total += resp.data['data'][i]['viewer_count'];
}
cursor = resp.data['pagination']['cursor'];
}