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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -