How to check if YouTube channel is streaming live

后端 未结 3 1234
一个人的身影
一个人的身影 2020-11-27 04:27

I can\'t find any informations to check if a YouTube channel is actually streaming or not. With Twitch you just need the channel name, and with the API you can check if ther

3条回答
  •  Happy的楠姐
    2020-11-27 05:19

    I know this is old but I figured it out myself with php.

    $API_KEY = 'your api3 key';
    $ChannelID = 'the users channel id';
    
    $channelInfo = 'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId='.$ChannelID.'&type=video&eventType=live&key='.$API_KEY;
    
    $extractInfo = file_get_contents($channelInfo);
    $extractInfo = str_replace('},]',"}]",$extractInfo);
    $showInfo = json_decode($extractInfo, true);
    
    if($showInfo['pageInfo']['totalResults'] === 0){
    
    echo 'Users channel is Offline';
    
    }else{
    
    echo 'Users channel is LIVE!';
    
    }
    

提交回复
热议问题