I wrote this code
$url = 'https://www.googleapis.com/youtube/v3/videos?key=MY_SECRET_KEY&part=snippet,statistics&id=yZj_EC8C5Ng';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_REFERER, 'http://niezaleznylublin.pl/');
curl_setopt($curl, CURLOPT_HEADER, false);
$json = curl_exec($curl);
curl_close($curl);
$obiekt=json_decode($json);
echo '<h1>'.$obiekt->items[0]->snippet->title.'</h1>';
echo '<img src="'.$obiekt->items[0]->snippet->thumbnails->standard->url.'"/>';
echo '<p>'.$obiekt->items[0]->snippet->description.'</p><br />';
echo '<h3>TAGI:</h3>';
echo '<p>';
foreach ($obiekt->items[0]->snippet->tags as $items) {
echo $items.', ';
}
echo'</p>';
echo $obiekt->items[0]->snippet->liveBroadcastContent;
echo '<br /><br /><br />';var_dump($obiekt);
It works well until my Youtube project is open to use with any site. When i try to add restriction to site from which i run my script ... *niezaleznylublin.pl/**(one asterisk here) var_dump object contains this data ...
object(stdClass)#1 (1) { ["error"]=> object(stdClass)#2 (3) { ["errors"]=> array(1) { [0]=> object(stdClass)#3 (4) { ["domain"]=> string(11) "usageLimits" ["reason"]=> string(16) "ipRefererBlocked" ["message"]=> string(254) "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed." ["extendedHelp"]=> string(37) "https://console.developers.google.com" } } ["code"]=> int(403) ["message"]=> string(254) "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed." } }
Funny thing is that when I'm trying JQuery script from site below everything is working fine with or without page restriction
http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html