php - YouTube API : Displaying thumbnails of each video. ..?

标签 php youtube youtube-api

您好,有人可以帮助我以正确的方式从我拉入的 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/

相关文章:

python - 更改 noauth_local_webserver 的默认状态?

python - 没有用户 OAuth 过程的 YouTube API

php - mysql的字符集问题

html - HTML5视频标签youtube

python - 为什么我在使用 Python 请求模块向 YouTube API v3 发出 POST 请求时得到 "Request is missing required authentication credential"?

Cocoa:在 WebView 中单击 "Watch on YouTube"不会执行任何操作

api - Zend_Gdata_ClientLogin::getHttpClient 问题

php - Mysql事件使用php脚本

php - 在不使用列名作为引用的情况下回显整个表

php - 如何根据 SQL/php 中另一列的多个值从一列中选择单个值