Get a users latest youtube videos?

后端 未结 3 1307
星月不相逢
星月不相逢 2021-02-06 12:09

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
相关标签:
3条回答
  • 2021-02-06 12:23

    YouTube has got an API available. You can see the reference here: https://code.google.com/apis/youtube/2.0/reference.html

    0 讨论(0)
  • 2021-02-06 12:25

    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 讨论(0)
  • 2021-02-06 12:30

    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

    0 讨论(0)
提交回复
热议问题