6

Non riesco a trovare alcuna informazione per verificare se un canale YouTube è effettivamente in streaming o meno. Con Twitch hai solo bisogno del nome del canale e con l'API puoi controllare se c'è un live o no.Come verificare se il canale YouTube è in streaming dal vivo

Non voglio usare OAuth, normalmente è sufficiente una chiave API pubblica. Come controllare i video di un canale, voglio sapere se il canale è in streaming.

risposta

15

È possibile eseguire questa operazione utilizzando search.list e specificando l'ID del canale, impostando il tipo su video e impostando eventType su live.

Per esempio, quando ho cercato:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCXswCcAMb5bvEUIDEzXFGYg&type=video&eventType=live&key=[API_KEY]

ho ottenuto il seguente:

{ 
"kind": "youtube#searchListResponse", 
"etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/gE5P_aKHWIIc6YSpRcOE57lf9oE\"", 
"pageInfo": { 
    "totalResults": 1, 
    "resultsPerPage": 5 
}, 
"items": [ 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/H-6Tm7-JewZC0-CW4ALwOiq9wjs\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "W4HL6h-ZSws" 
    }, 
    "snippet": { 
    "publishedAt": "2015-09-08T11:46:23.000Z", 
    "channelId": "UCXswCcAMb5bvEUIDEzXFGYg", 
    "title": "Borussia Dortmund vs St. Pauli 1-0 Live Stream", 
    "description": "Borussia Dortmund vs St. Pauli Live Stream Friendly Match.", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/W4HL6h-ZSws/default.jpg" 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/W4HL6h-ZSws/mqdefault.jpg" 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/W4HL6h-ZSws/hqdefault.jpg" 
    } 
    }, 
    "channelTitle": "", 
    "liveBroadcastContent": "live" 
    } 
    } 
] 
} 
+1

ma possiamo avere l'id del video vapore? – mpgn

+2

Puoi trovare l'ID se guardi la risorsa 'items' ->' id' -> 'videoId'. Nell'esempio che ho postato sopra, l'ID del flusso video è 'W4HL6h-ZSws'. –

+0

Grazie mille. – PaulELI

4

So che questo è vecchio, ma ho capito io con 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!'; 

} 
Problemi correlati