Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2016 19:59
Show Gist options
  • Save anonymous/224db6004c2b3c5ae40ec2b1f718ac34 to your computer and use it in GitHub Desktop.
Save anonymous/224db6004c2b3c5ae40ec2b1f718ac34 to your computer and use it in GitHub Desktop.
this is the multidimensional-array
###############################
{
"kind": "youtube#searchListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/hys1HflQr8XiiYpydVnkJA-oudA\"",
"regionCode": "DE",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/VriB3fWVmI-YytLihGJXqyohdgY\"",
"id": {
"kind": "youtube#video",
"videoId": "dnKMDe-i6HA"
},
"snippet": {
"publishedAt": "2015-08-26T17:35:58.000Z",
"channelId": "UCN32fF7zoJxEUBKonRiIIRw",
"title": "heut kein Frühstück, muss Credits verdienen",
"description": "Lockeres zocken zum wach werden und bissel farmen für ein neues Raumschiff.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/dnKMDe-i6HA/default_live.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/dnKMDe-i6HA/mqdefault_live.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/dnKMDe-i6HA/hqdefault_live.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "KompetenzTeam",
"liveBroadcastContent": "live"
}
}
]
}
#################################
this is my try to get the value of "liveBroadcastContent" is "live" or not
$request = json_decode( @file_get_contents( 'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCN32fF7zoJxEUBKonRiIIRw&type=video&eventType=live&key=AIzaSyDN4O5RQZf-o2UkgNNRCcyxJPZETcNJeCo' ), true );
$key1 = 'liveBroadcastContent';
$val1 = 'live';
function find_key_value($array, $key, $val)
{
foreach ($array as $item)
{
if (is_array($item) && find_key_value($item, $key, $val)) return true;
if (isset($item[$key]) && $item[$key] == $val) return true;
}
return false;
};
$result = find_key_value($request, $key1, $val1);
if($result = "1")
{
echo '<img src="images/template_related/youtube_is_LIVE_light.png" />';
}
else
{
echo '<img src="images/template_related/youtube_not_LIVE_light.png" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment