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

时间:2015-07-14 10:23:49

标签: php jquery video youtube-api

我写了这段代码

$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

1 个答案:

答案 0 :(得分:0)

LOL这很奇怪。我今天试过脚本,没有改变任何东西,现在效果很好。这里涉及某种传播,或者确实谷歌人会在帮助中心看到那些youtube-api主题。

尽管如此,感谢所有回复。