How to embed Youtube live chat with url permanent?

前端 未结 2 1718
终归单人心
终归单人心 2021-01-11 13:18

The embed URL for a channel\'s live stream is:

https://www.youtube.com/embed/live_stream?channel=CHANNEL_ID

and it works but if I want to e

2条回答
  •  别那么骄傲
    2021-01-11 13:59

    You could get the video ID using PHP like this:

    getMessage();
    }
    
    // The method which finds the video ID
    function getLiveVideoID($channelId)
    {
        $videoId = null;
    
        // Fetch the livestream page
        if($data = file_get_contents('https://www.youtube.com/embed/live_stream?channel='.$channelId))
        {
            // Find the video ID in there
            if(preg_match('/\'VIDEO_ID\': \"(.*?)\"/', $data, $matches))
                $videoId = $matches[1];
            else
                throw new Exception('Couldn\'t find video ID');
        }
        else
            throw new Exception('Couldn\'t fetch data');
    
        return $videoId;
    }
    

提交回复
热议问题