I am having issues with YouTube Data API. I'm working on a PHP function to retrieve all videos information in JSON format from a YouTube channel, and then put that into a file.

So far I managed to call the API and retrieve the first 50 videos info; am also knowing the method to create the file.

I know that I have to use the `nextPageToken` parameter to loop the function until there is no `nextPageToken`, but I'm stuck. I've seen a lot of similar posts with this problem, but none of them really helped me.

To sum up, I need help to:

* use `nextPageToken` to collect information after 50 videos;
* collect this information each turn of the loop.

So far the code I found and used:

```
function youtube_search($API_key, $channelID, $max_results, $next_page_token=''){
    $myQuery = "https://www.googleapis.com/youtube/v3/search?key=".$API_key."&channelId=".$channelID."&part=snippet,id&order=date&maxResults=".$max_results;
    $ch = curl_init();

        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $myQuery);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $response = curl_exec($ch);

        curl_close($ch);

        $data = json_decode($response);

        if(!empty($data->nextPageToken)){

       return youtube_search($API_key, $channelID, $max_results, $searchResponse['nextPageToken']);
     }

}

youtube_search($API_key, $channelID, $max_results, $next_page_token='');

```

Thank you for helping (am a humble beginner -\_-).