Search code examples
phpyoutube-apiplaylist

Retrieving a Youtube user's playlists with PHP


Could you offer me an example about how to retrieving a Youtube user's playlists with PHP?

I have read the Developer's Guide: Data API Protocol – Playlists, but I didn't understood.

This is what I would like to do:

enter image description here

Each tab is a play list where I show the player list. In this case we're placed ino 'Porto' tab. At the right I show the videos in the list and below the player list, show the comments.

Is it possible?


Solution

  • //Playlist: PLAD954BCB770DB285, remove PL from name
    $playlist_id = "AD954BCB770DB285";
    $url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json";
    $data = json_decode(file_get_contents($url),true);
    $info = $data["feed"];
    $video = $info["entry"];
    $nVideo = count($video);
    
    echo "Playlist Name: ".$info["title"]['$t'].'<br/>';
    echo "Number of Videos (".$nVideo."):<br/>";
    
    for ($i = 0; $i < $nVideo; $i++){
        echo "Name: ".$video[$i]['title']['$t'].'<br/>';
        echo "Link: ".$video[$i]['link'][0]['href'].'<br/>';
        echo "Image: <img src='".$video[$i]['media$group']['media$thumbnail'][1]['url']."' /><br />";
    }