我使用以下PHP脚本来获取播放列表中每个YouTube视频的标题和说明,但我无法弄清楚如何获取视频的YouTube ID或网址。我需要什么查询?
<?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 ?>
答案 0 :(得分:1)
<?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 ?>
你已经有了正确的痕迹。你需要的属性是yt $ videoid,我刚才在这里添加。