Youtube API -检索单个视频信息- JS工作正常,PHP给出限制错误


Youtube API - retrieve single video info - JS works fine, PHP gives restriction error

我写了这段代码

$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);

它工作得很好,直到我的Youtube项目开放使用与任何网站。当我试图添加限制的网站,我运行我的脚本…*niezaleznylublin.pl/**(这里有一个星号)Var_dump对象包含这个数据…

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." } }   

有趣的是,当我从下面的站点尝试JQuery脚本时,一切都工作得很好,有或没有页面限制

http://salman-w.blogspot.com/2010/01/retrieve-youtube-video-title.html

哈哈,这很奇怪。我今天尝试了脚本,没有改变任何东西,现在工作得很好。要么这里涉及某种传播,要么谷歌人确实观看了他们在帮助中心声称的那些youtube-api主题。

谢谢大家的回复。