Laurent
Laurent

Reputation: 61

How to get number of video views with YouTube API V3?

i use this code to achieve this but this don't work :

 <?php
$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=hqepb5hzuB0&key={YOUR-API-KEY}");
$JSON_Data = json_decode($JSON);
$views = $json_data->{'entry'}->{'yt$statistics'}->{'viewCount'};
echo $views;
?>

Thanks

Upvotes: 3

Views: 8024

Answers (1)

theduck
theduck

Reputation: 2617

Try something like this:

$JSON = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=hqepb5hzuB0&key={YOUR-API-KEY}");
$json_data = json_decode($JSON, true);
echo $json_data['items'][0]['statistics']['viewCount'];

Upvotes: 9

Related Questions