I've just started using the API v3 to get individual videos viewCounts. But the code I'm using only works on my local sites and doesn't work at all as soon as I upload. Here is the code:
<?php
$vId = '1URvDyzh8uI';
$dur = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=contentDetails,statistics&id=$vId&key={myAPIkey}");
$video =json_decode($dur, true);
foreach ($video['items'] as $vidCount) {
$vCount= $vidCount['statistics']['viewCount'];
}
echo $vCount;
?>
Am i missing something to make it work on live sites? I've looked into authentication being a possible problem, but have tried and failed in using it. Any helped would be greatly appreciated.
Halcyon helped with his comment. Just change "allow_url_fopen" to On in the php.ini and it works!