您好,有人可以帮助我以正确的方式从我拉入的 channel 中获取每个视频的 default.jpg 图像吗?
<?php
$url = 'http://gdata.youtube.com/feeds/api/users/utahblaze/uploads?orderby=updated&max-results=8';
$xml = simplexml_load_file($url);
foreach ($xml->entry as $entry) :
$kids = $entry->children('http://search.yahoo.com/mrss/');
$attributes = $kids->group->content[0]->attributes();
$flv = $attributes['url'];
$attributes = $kids->group->player->attributes();
$link = $attributes['url'];
?>
<a href="<?=$link?>">test</a?
<?php endforeach; ?>
最佳答案
这里是如何使用 Zend Framework 的 GData Youtube 类获取视频的图像 url 的示例。
<?php
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->videoQuery = 'cat';
$query->startIndex = 10;
$query->maxResults = 20;
$query->orderBy = 'viewCount';
$videoFeed = $yt->getVideoFeed($query);
foreach ($videoFeed as $videoEntry) : ?>
<div class="video">
<span>Title: <?php echo $videoEntry->getVideoTitle();?><span><br />
<span>Description:<?php echo $videoEntry->getVideoDescription();?> </span> <br/>
<?php $videoThumbnails = $videoEntry->getVideoThumbnails(); ?>
<img alt="video-thumbnail" src="<?php echo $videoThumbnails[0]['url'];?>" />
</div>
<?php endforeach; ?>
正如您所看到的,getVideoThumbnails() 方法为您提供了该视频的缩略图数组及其内部的 url。希望这会有所帮助。
关于php - YouTube API : Displaying thumbnails of each video. ..?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9301806/