Getting a YouTube videos tags using the YouTube api in PHP is actually quiet easy, just follow this guide. You will need your YouTube api key!
It easy to just make a function, this also helps with repeat use!
functions.php
function video_tag($tag, $video_id) { $api_key = 'YOU API KEY HERE'; $data = json_decode(file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" . $video_id . "&key=".$api_key.""), true); $tag = $data['items'][0]['snippet']['tags'][$tag]; return $tag; }
Here we have a function that will return the tag depending on your tag key. 0 is the first tag… 1 is the next and so forth.
An example for this function being used on this Casey Neistat video
include('functions.php'); echo video_tag(1,'0-7wMD5ISIs');//abandoned mall echo video_tag(3,'0-7wMD5ISIs');//samsung
His second tag for the video was “abandoned mall and his fourth tag was “samsung”.
You can see the result of the whole api call the function does in this spoiler:
And that’s how to easily get a YouTube videos tags using the YouTube api in PHP.