Home » PHP

To fetch the latest youtube video from user channel using php

22 April 2013 No Comment
Share on Facebook

If you need to create a widget & showcase the latest video uploaded in youtube channel to your users. Can be in your website or advertisements or anywhere, it is now possible with youtube API.


Youtube feeds

The API returns a videos feed in response to a request to search for videos. A videos feed contains a maximum of 999 entries. To retrieve search results, send an API request to the following URL:


Videos uploaded by a specific user

To request a feed of all videos uploaded by the currently logged-in user, send a GET request to the following URL. This request requires an authentication token, which enables YouTube to identify the user.


Learn more:

Using PHP to fetch latest youtube channel video:

We are going to use php code to fetch latest youtube user channel video of “officialpsy”

PHP code to fetch youtube channel:

$feedURL = 'http://gdata.youtube.com/feeds/api/users/officialpsy/uploads?max-results=1';
$sxml = simplexml_load_file($feedURL);
	foreach ($sxml->entry as $entry) {
      $media = $entry->children('media', true);
      $watch = (string)$media->group->player->attributes()->url;
      $thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
      $videoURL = str_replace("&feature=youtube_gdata_player","?feature=player_detailpage",$watch);
	  $videoURL = str_replace("watch?v=","embed/",$videoURL);
      <div class="videoitem">
        <div class="videothumb">
        	<iframe width="470" height="360" src="<?php echo $videoURL; ?>" frameborder="0" allowfullscreen></iframe>
        <div class="videotitle">
            <h3><a href="<?php echo $watch; ?>" class="watchvideo"><?php echo $media->group->title; ?></a></h3>
            <p><?php echo $media->group->description; ?></p>
<?php } ?>


In this sample snippet code we have seen how to get the lastest youtube video from user channel.


We don't share your email anywhere, grab our rss via feedburner

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.