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

Youtube API-检索单个视频信息-JS工作正常,PHP给出限制错误,php,jquery,video,youtube-api,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

我写了这段代码

$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);
有趣的是,当我从下面的站点尝试JQuery脚本时,无论有无页面限制,一切都可以正常工作


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


尽管如此,还是要感谢所有的回复。

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


尽管如此,还是要感谢所有的回复。

您是否尝试将Referer标题放入您的curl请求中?我想当使用PHP的curl时,youtube无法确定请求来自何处。我忘了这个代码副本不包含那个。在Chrome中更新OpenInspector,启动jQuery请求,切换到inspector的网络选项卡并找到请求。在该请求的上下文菜单下,您将有“复制为卷曲”选项。这可能会提示您在PHP的curl中缺少什么。您可能还想将此curl命令添加到您的问题中。您是否尝试将Referer头放入您的curl请求中?我想当使用PHP的curl时,youtube无法确定请求来自何处。我忘了这个代码副本不包含那个。在Chrome中更新OpenInspector,启动jQuery请求,切换到inspector的网络选项卡并找到请求。在该请求的上下文菜单下,您将有“复制为卷曲”选项。这可能会提示您在PHP的curl中缺少什么。您可能还希望将此curl命令添加到问题中。
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." } }