doujiu8918 2015-07-14 10:23
浏览 59

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

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

  • 写回答

1条回答 默认 最新

  • dongxingguo1978 2015-07-15 07:36
    关注

    LOL this is odd. I tried script today, havent change anything and works well now. Either some kind of propagation is involved here or indeed Google guys watch those youtube-api topics as they claim in help center.

    Nevertheless thanks for all responses.

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值