【发布时间】:2020-08-17 22:45:44
【问题描述】:
我想将我频道中的最新视频放到我的网站上。这将返回以下错误:
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UCD---------&maxResults=1&key=A---------------): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in C:\xampp\htdocs\inc\latestVideo.php on line 15
我的代码:
<?php
$API_key = 'A---------------';
$channelID = 'UCD---------';
$maxResults = 1;
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
if(isset($item->id->videoId)){
echo '<div class="youtube-video">
<iframe width="280" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h2>'. $item->snippet->title .'</h2>
</div>';
}
?>
【问题讨论】:
-
它指出有一个403错误,您不能以您尝试的方式访问该URL