Is there a way to get a list of all youtube videos in a channel into a PHP array. I need the embed URL, Video Title and Description.
How could I do this?
I have used
<?php
$source = 'http://gdata.youtube.com/feeds/api/videos?author=blah';
// load as string
$xmlstr = file_get_contents($source);
$xmlcont = new SimpleXMLElement($xmlstr);
foreach($xmlcont as $url)
{
echo "{$url->id}>{$url->title}>{$url->content}>{$url->published}>
";
}
?>
Start here: https://developers.google.com/youtube/v3/
That api should give you what you need.
The Youtube API is quite easy to use, in the other hand, if you do not want to have to deal with HTTP, cache, url forgery and format manipulation, I recommand the Zend GData lib: http://framework.zend.com/manual/1.12/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt->getUserUploads('liz');
Hard to be easier than two lines of code :)
you may try this...
<?php
if(!(empty($_REQUEST[v])))
{
$video=$_REQUEST[v];
$autoval=1;
}
else
{
$video="koDeTEM7Uv0";
$autoval=0;
}
?>
<div style="float:left; height:182px;">
<object width="268" height="182">
<param name="movie" value="http://www.youtube.com/v/<?php echo $video."&autoplay=".$autoval;?>&fs=0&hl=en_US&ap=%2526fmt%3D18"></param>
<param name="allowFullScreen" value="true"></param> <param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/<?php echo $video."&autoplay=".$autoval;?>&fs=0&hl=en_US&ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="268" height="182"></embed>
</object>
</div>
<div style="clear:both; height:7px;"></div>
<?php
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/users/Asterhealthcare/uploads?max-results=3&start-index=1&strict=true';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
?>
<!-- <h1><?php //echo $sxml->title; ?></h1>-->
<?php
// iterate over entries in feed
$total=count($sxml);
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
//get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
$watch=str_replace(array('http://www.youtube.com/watch','&feature=youtube_gdata_player'),'',$watch);
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];
// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');
if ($gd->rating) {
$attrs = $gd->rating->attributes();
$rating = $attrs['average'];
} else {
$rating = 0;
}
?>
<a href="<?php echo $watch; ?>"><img src="<?php echo $thumbnail;?>" height="48px" width="82px" border="1" /></a>
<?php
}
?>