php - How to get number of video views with YouTube API V3? -
i use code achieve 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
try 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'];
Comments
Post a Comment