How to get a Youtube channel RSS feed after 2015 April 20 (without v3 API)?

后端 未结 16 1196
野趣味
野趣味 2020-12-22 17:14

Now that API v2 is gone, what would be a way to get a simple RSS feed of a channel, without v3 API? I\'m open to Yahoo Pipes or any workaround that is simpler than creating

16条回答
  •  我在风中等你
    2020-12-22 17:41

    I think there are some changes in youtube response so i make some changes to get channel id from rss feed using Curl.

    $channel_id = 'XXXXXXXX'; // put the channel id here
    
    //using curl
    $url = 'https://www.youtube.com/feeds/videos.xml?channel_id='.$channel_id.'&orderby=published';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    $response  = curl_exec($ch);
    curl_close($ch);
    
    $response=simplexml_load_string($response);
    $json = json_encode($response);
    $youtube= json_decode($json, true);
    
    $count = 0;
    if(isset($youtube['entry']['0']) && $youtube['entry']['0']!=array())
    {
        foreach ($youtube['entry'] as $k => $v) {
            $yt_vids[$count]['id'] = str_replace('http://www.youtube.com/watch?v=', '', $v['link']['@attributes']['href']);
            $yt_vids[$count]['title'] = $v['title'];
            $count++;
        }
    }
    else
    {
        $yt_vids[$count]['id']=str_replace('http://www.youtube.com/watch?v=', '', $youtube['entry']['link']['@attributes']['href']);
        $yt_vids[$count]['title']=$youtube['title'];
    }
    echo "
    ";
    print_r($yt_vids);
    

提交回复
热议问题