dqab0824 2013-11-16 20:59
浏览 129
已采纳

从YouTube播放列表中获取所有视频ID到PHP阵列

My goal is to use a playlist ID to get the video ID of each video within that playlist.

I'm having trouble figuring out YouTube's API (I'm a relatively new programmer).

Basically, I want to:

  1. Send an XML request to http://gdata.youtube.com/feeds/api/playlists/ID_OF_PLAYLIST
  2. Using the response (which is the part I don't understand how to navigate), append all the video IDs to an array.

Seems pretty straightforward. I've been grabbing the information from YouTube using simplexml_load_file($url); in case that is important.

Thanks for the help!

  • 写回答

1条回答 默认 最新

  • douzong3599 2013-11-16 21:45
    关注

    Here you go, I made an example:

    <?php
    $data = file_get_contents('http://gdata.youtube.com/feeds/api/playlists/PL4BC045240D2FB11B/?v=2&alt=json&feature=plcp');
    
    if (!$data)
        throw new Exception("Data retrieval failed.");
    
    $dataAsArray = json_decode($data);
    $feed = $dataAsArray->feed->entry;
    
    $videoID_array = array();
    
    if(count($feed))
    {
        foreach($feed as $item)
            array_push($videoID_array, $item->{'media$group'}->{'yt$videoid'}->{'$t'});
    }
    
    print_r($videoID_array);
    
    ?>
    

    Where PL4BC045240D2FB11B of course is the Playlist ID! Example PHPFiddle

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?