开发者

Get a users latest youtube videos?

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 t开发者_开发百科o 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 has got an API available. You can see the reference here: https://code.google.com/apis/youtube/2.0/reference.html


http://code.google.com/apis/gdata/articles/php_client_lib.html

and

http://code.google.com/apis/youtube/2.0/developers_guide_php.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜