Danny Cooper
Danny Cooper

Reputation: 355

Extract Video URL or ID From a YouTube Playlist Using YouTube API

I am using the following PHP script to grab the title and description for each of the YouTube videos in a playlist, but I have not been able to figure out how to grab the YouTube ID or url for the videos. What is the query that I need?

<?php $cont = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/playlists/AtWAMBKrZSRGVsVxlcW74lU7JB31954X/?v=2&alt=json&feature=plcp')); ?>
<?php $feed = $cont->feed->entry; ?>
<?php if(count($feed)): foreach($feed as $item): // youtube start ?>
   <?php echo $item->title->{'$t'}  ?> <br />
   <?php echo $item->{'media$group'}->{'media$description'}->{'$t'}  ?>
<?php endforeach; endif; // youtube end ?>

Upvotes: 0

Views: 2640

Answers (1)

thpl
thpl

Reputation: 5910

<?php $cont = json_decode(file_get_contents('http://gdata.youtube.com/feeds/api/playlists/AtWAMBKrZSRGVsVxlcW74lU7JB31954X/?v=2&alt=json&feature=plcp')); ?>
<?php $feed = $cont->feed->entry; ?>
<?php if(count($feed)): foreach($feed as $item): // youtube start ?>
    <?php echo $item->title->{'$t'}  ?> <br />
    <?php echo $item->{'media$group'}->{'media$description'}->{'$t'}  ?>
    <?php echo $item->{'media$group'}->{'yt$videoid'}->{'$t'} ?>
<?php endforeach; endif; // youtube end ?>

You have already had the right trace. The property you need here is yt$videoid which I just added here.

Upvotes: 1

Related Questions