Looping through the json with PHP

Is there a way to loop through the json pages with the pagination ? This may be a little bit off topic, but at this point I have no one to turn to. My code so far:

    $channelsApi = 'https://api.twitch.tv/helix/users/follows? 
    $channelName = '';
    $ch = curl_init();
    curl_setopt_array($ch, array(
    "Authorization: Bearer ".$_GET['fragmentaccess_token'].""
    CURLOPT_URL => $channelsApi . $channelName
    $response = curl_exec($ch);
     // echo $response;
     $json = json_decode($response, true);

I was able to make it through other pages if i simply

 foreach ($json['pagination'] as $curs){
 if(isset($curs) && $json['data'] != NULL){

  //     $connection = new mysqli("localhost","root","","twitchun");
  $channelsApi = 'https://api.twitch.tv/helix/users/follows? 

But i do not want to copy paste my code a million times if i have to go through a million names. Thank you in advance !

Hey! I’m not sure how you would go about this. I wish I had a better solution for you, but this article may be able to help: https://medium.com/square-corner-blog/tips-and-tricks-for-api-pagination-5cacc6f017da

1 Like

Well I’ll look into it. But I am very grateful for the answer

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.