Search code examples
youtubefeedyoutube-data-api

www.youtube.com/feeds/videos.xml?playlist_id Only giving last 15 videos


I want to get last 50 videos from www.youtube.com/feeds/videos.xml?playlist_id, Currently I can only retrieve last 15 videos. I have tried max-result parameter, but it failed.


Solution

  • Instead of above method I have found another way to fetch youtube playlist videos, here it is

    <?php
    $playlistId = 'Playlist Id here';
    $maxResults = 50;
    $apiKey = 'youtube api key here';
    
    $string = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId='.$playlistId.'&maxResults='.$maxResults.'&key='.$apiKey.''));
    
    //echo '<pre>'; print_r($string);
    
    foreach($string->items as $item) {
    $video_id = $item->snippet->resourceId->videoId;
    }
    ?>