Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a users latest youtube videos?

Tags:

php

youtube

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?

like image 227
wesbos Avatar asked Jul 23 '10 19:07

wesbos


1 Answers

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

like image 107
chanchal1987 Avatar answered Oct 11 '22 13:10

chanchal1987