Get your Youtube channel playlist

Apr 04 2015

Get your Youtube channel playlist

Download at github


I made a quick little example to read a YouTube user’s video feed that really easy to use.  To request a feed of all videos uploaded by another user, send a GET request to the following URL. This request does not require authentication. In the URL above, you should replace the text userId with the user's YouTube user ID.


Use below lines of code to get all youtube channel videos as xml format.

$feedURL = '';

$sxml = simplexml_load_file($feedURL);


Now parse the XML feed and get the video url as shown

foreach ($sxml->entry as $entry) {

                    $media = $entry->children('');

                    // get video player URL

                    $attrs = $media->group->player->attributes();

                    $watch = $attrs['url'];                   



To  get the video thumbnail use bellow code

foreach ($sxml->entry as $entry) {

                    $media = $entry->children('');

                    // get video thumbnail

                    $attrs = $media->group->thumbnail[0]->attributes();

                    $thumbnail = $attrs['url'];



To get the video streaming time use bellow code

foreach ($sxml->entry as $entry) {

                    $media = $entry->children('');

                           // get video length

                    $yt = $media->children('');

                    $attrs = $yt->duration->attributes();

                    $length = $attrs['seconds'];      



To get the video visit statistics use bellow code

foreach ($sxml->entry as $entry) {

                    $media = $entry->children('');

                        // get viewer statistics  

$yt = $entry->children('');

                    $attrs = $yt->statistics->attributes();

                    $viewCount = $attrs['viewCount'];



To get the video rating statistics use bellow code

foreach ($sxml->entry as $entry) {

                    $media = $entry->children('');

                        // get video ratings

                    $gd = $entry->children('');

                    if ($gd->rating) {

                        $attrs = $gd->rating->attributes();

                        $rating = $attrs['average'];

                    } else {

                        $rating = 0;




Coming to the UI part, add simple html in between foreach loop to display feed in your website.

<div class="col-lg-4 col-sm-6 col-xs-12 mygrid">

                        <a href="<?php echo $watch; ?>" target="_blank">

                            <img src="<?php echo $thumbnail; ?>" class="thumbnail img-responsive" alt="<?php echo $media->group->title; ?>">


                        <a href="<?php echo $watch; ?>" target="_blank"><?php echo $media->group->title; ?></a><br/>

                        <span>Views: <?php echo $viewCount; ?></span>

                        <span class="attr" <?php printf('%0.2f', $length / 60); ?> min.</span>


I used bootstrap framework to show your feed beautiful and responsive way. Now combine all the above steps to use show feed in your website. Click on demo link , download source code and use it.

Like my official facebook at

Leave a Reply