【发布时间】:2021-01-09 01:11:38
【问题描述】:
我找到并修改了一个用于显示 youtube 视频的 sn-p。
我在 BootStrap 后面设置它,使用模型在点击时弹出。
我遇到的问题是弄清楚为什么第四个项目没有显示弹出模型。
如果您想查看问题的实际效果,可以单击底部列出的第四项:https://phattboiibamm.com/
<?php
//Get videos from channel by YouTube Data API
$API_key = 'SECRET'; //my API key
$channelID = 'SECRET'; //my channel ID
$maxResults = 4;
$video_list = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
$latest = $video_list->items[0]->id->videoId;
$thelist = $video_list->items;
?>
这是循环
<?php
foreach ($thelist as $item) {
//Embed video
if (isset($item->id->videoId)) {
//echo '<div class="embed-responsive embed-responsive-21by9">
// <iframe class="embed-responsive-item" width="280" height="150" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
//<h4>'. $item->snippet->title .'</h4>
// </div>';
echo "\n \n <br><br> \n \n ";
echo "\n \n <!-- Image --> \n \n";
echo "\n \n <br><br> \n \n ";
echo '<img src="'.$item->snippet->thumbnails->high->url.'" width="250px" height="250px" alt="..." class="img-thumbnail m-1" data-toggle="modal" data-target="#'.$item->id->videoId.'">';
echo "\n \n <br><br> \n \n ";
echo "\n \n <!-- Model --> \n \n";
echo "\n \n <br><br> \n \n ";
echo '<div class="modal fade bd-example-modal-lg" id="'.$item->id->videoId.'" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<center><h4>'. $item->snippet->title .'</h4></center>
<div class="embed-responsive embed-responsive-16by9 z-depth-1-half">
<iframe class="embed-responsive-item p-1" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
</div>';
}
} ?>
【问题讨论】:
标签: php youtube-api