I have the following code:
<?php
$id = 'bsTY5cTi3nI';
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" . $id . "&key=...");
$JSON_Data = json_decode($JSON);
$views = $JSON_Data->{"entry"}->{'yt$statistics'}->{'viewCount'};
echo $views;
?>
I want to get the number of views of a YT video with PHP. But I get the following error message:
Notice: Undefined property: stdClass::$entry in D:\XAMPP\htdocs\Project1\WatchToGether\test2.php on line 5
Notice: Trying to get property 'yt$statistics' of non-object in D:\XAMPP\htdocs\Project1\WatchToGether\test2.php on line 5
Notice: Trying to get property 'viewCount' of non-object in D:\XAMPP\htdocs\Project1\WatchToGether\test2.php on line 5
Could someone please help me with my problem. I would appreciate answers.