So but how is it to sum the viewer_count with json?
Thatâs a âhow do I do basic math in programming language of choiceâ question, not a API question
ah okay thanks, but can you tell even, maybe?
- Fetch page 0
 - Iterate each record
 - viewers = viewers + this records viewers
 - fetch next page
 - goto step 2
 
so can not understand this?
so i am very new in json yet! 
so where in the code above to set the sum?
JSON has no relevant here.
I canât give you the code you need to use because I donât know what language you are working in, and then if I just give you the answer you wonât have learned anything. This is basic data manipulation in any language.
You code above doesnât have enough code to answer that
so thanks!
so thats all about the request:
 $channelsApi2 = 'https://api.twitch.tv/helix/streams?first=100&language=de&game_id=';
 $ch2 = curl_init();
 $apiVers2 = '&api_version=5';
 
 curl_setopt_array($ch2, array(
    CURLOPT_HTTPHEADER => array(
       'Client-ID: ' . $clientId
    ),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $channelsApi2 . $gameID . $apiVers2
 ));
 $response2 = curl_exec($ch2);
$resp2 = json_decode($response2);
$viewerCount2 = $resp2->data[0]->viewer_count;
            so set sum somewhere here?
$viewerCount2 = array_sum($resp2->data[0]->viewer_count);
this maybe?
 $count = 0;
 $channelsApi2 = 'https://api.twitch.tv/helix/streams?first=100&language=de&game_id=';
 $ch2 = curl_init();
 
 curl_setopt_array($ch2, array(
    CURLOPT_HTTPHEADER => array(
       'Client-ID: ' . $clientId
    ),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $channelsApi2 . $gameID
 ));
 $response2 = curl_exec($ch2);
 $resp2 = json_decode($response2);
 foreach ($resp2->data as $strim) {
   $count += $strim->viewer_count;
 }
 // get next page
            $clientID is declared somewhere else!
Thanks was very helpful!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.