获取用户最新的 YouTube 视频? [英] Get a users latest youtube videos?

查看:27
本文介绍了获取用户最新的 YouTube 视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从用户的 youtube 名称或网址中获取以下内容的方法.

  1. 缩略图
  2. 指向 youtube.com 上的视频的链接
  3. 视频标题

需要用PHP来做.是否有一些我可以使用的 youtube api 或者是我最好的选择之类的简单馅饼?

解决方案

看代码

entry as $entry) {$media = $entry->children('media', true);$watch = (string)$media->group->player->attributes()->url;$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;?><div class="videoitem"><div class="videothumb"><a href="<?php echo $watch; ?>"class="watchvideo"><img src="<?php echo $thumbnail;?>"alt="<?php echo $media->group->title; ?>"/></a></div><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 $i++;if($i==3) { echo '<div class="clear small_v_margin"></div>';$i=0;} } ?

<块引用>

从帖子中复制代码SimpleXML循环有效但中途中断

它将为用户提供所有 youtube 视频.现在很容易开发你自己的.从 https://code.google.com/apis/了解有关 YouTube API 的更多信息youtube/2.0/reference.html

I'm looking for a way get the following from a users youtube name or url.

  1. thumbnail
  2. link to video on youtube.com
  3. Title of the video

Need to do it with PHP. Is there some youtube api I can use or is something like simple pie my best bet?

解决方案

Look at the code

<?php
error_reporting(E_ALL);
$feedURL = 'http://gdata.youtube.com/feeds/api/users/USER-ID/uploads?max-results=50';
$sxml = simplexml_load_file($feedURL);
$i=0;
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;
      ?>
      <div class="videoitem">
        <div class="videothumb"><a href="<?php echo $watch; ?>" class="watchvideo"><img src="<?php echo $thumbnail;?>" alt="<?php echo $media->group->title; ?>" /></a></div>
        <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>
        </div>
      </div>      
<?php $i++; if($i==3) { echo '<div class="clear small_v_margin"></div>'; $i=0; } } ?>

Code is copied from the post SimpleXML loop works but breaks half way through

It will get a users all youtube videos. Now it is very easy to develop your own. Know more about YouTube API from https://code.google.com/apis/youtube/2.0/reference.html

这篇关于获取用户最新的 YouTube 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆