jcadima
7/19/2017 - 1:16 PM

Get Number of youtube views for video

Get Number of youtube views for video


<?php
	function get_youtube_views($video_ID) {
		$JSON = file_get_contents("https://gdata.youtube.com/feeds/api/videos?q={$video_ID}&alt=json");
		$JSON_Data = json_decode($JSON);
		$views = $JSON_Data->{'feed'}->{'entry'}[0]->{'yt$statistics'}->{'viewCount'};
		echo $views;
	}
 

// pass the youtube video ID 
get_youtube_views('5WEK6HgXBsQ');