Hi Reader's,
Welcome to FindNerd, today we are going to discuss how to get the video views from youtube using API in PHP ?
If you want to see the total counts of a views on youtube video by api, then you should use below code:
<?php
//here set the id from url and store in a variable
$video_ID = "video_id";
//here call file_get_contents()
$jsonURL = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id={$video_ID}&key=YOUR_KEY_HERE&part=statistics");
//here call json_decode()
$json = json_decode($jsonURL);
$views = $json->{'items'}[0]->{'statistics'}->{'viewCount'};
echo number_format($views,0,'.',',');
?>
In above example you have to pass your video_id and you can see total view of your video
0 Comment(s)