有没有办法将通道中所有YouTube视频的列表放到PHP数组中。我需要嵌入URL,视频标题和说明。
我怎么能这样做?
答案 0 :(得分:2)
从这里开始:https://developers.google.com/youtube/v3/
那个api应该能满足你的需要。
答案 1 :(得分:1)
Youtube API非常易于使用, 另一方面,如果你不想处理HTTP,缓存,url伪造和格式操作,我建议使用Zend GData lib:http://framework.zend.com/manual/1.12/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$videoFeed = $yt->getUserUploads('liz');
比两行代码更容易:)
答案 2 :(得分:0)
你可以试试这个......
<?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
}
?>
答案 3 :(得分:0)
我用过
<?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}>\r\n";
}
?>