用php显示youtube的私人视频

用php显示youtube的私人视频,php,Php,我试图在我的php项目中显示我上传到youtube的私人视频。以下是我的php代码 <?php //Get videos from channel by YouTube Data API $API_key = 'YOUR_YOUTUBE_API_KEY'; $channelID = 'YOUR_YOUTUBE_CHANNEL_ID'; $maxResults = 10; $videoList = json_decode(file_get_contents('https://www

我试图在我的php项目中显示我上传到youtube的私人视频。以下是我的php代码

<?php
//Get videos from channel by YouTube Data API
$API_key    = 'YOUR_YOUTUBE_API_KEY';
$channelID  = 'YOUR_YOUTUBE_CHANNEL_ID';
$maxResults = 10;

$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));


?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Videos from YouTube Channel </title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style type="text/css">
    .container{padding: 15px;}
    .youtube-video h2{font-size: 16px;}
    </style>
</head>
<body>
<div class="container">
    <div class="row">
    <?php
    foreach($videoList->items as $item){
        //Embed video
        if(isset($item->id->videoId)){
            echo '<div id="'. $item->id->videoId .'" class="col-lg-3 col-sm-6 col-xs-6 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>';
        }
    }
    ?>
    </div>
</div>
</body>
</html>
警告:为第31行的C:\xampp\htdocs\channels\index.php中的foreach()提供的参数无效


你能帮我解决这个问题吗?你的代码可能没有问题


您已经使用该api密钥超过了该帐户的使用限制,您的代码可能没有任何问题


如果您在
$api\u key='your\u YOUTUBE\u api\u key'中替换您的api\u key,那么您已经用该api key超出了该帐户的使用限制您可能还希望在“警告:文件获取内容(…”中执行此操作”-每个人都可以阅读。删除问题并重新开始。如果可能的话,我可能会在YT上更改该APIkey。我已经在YT上添加了原始api key,但在发布问题时,我无法发布原始ID。如果您将api key替换为
$api key='your_YOUTUBE_api_key';
您可能还希望在“警告:文件获取内容(…”中执行此操作-每个人都可以阅读。删除问题并重新开始。如果可能的话,可能会更改YT上的APIkey。我已经在该问题上添加了原始api key,但在发布问题时,我无法发布原始ID
Warning: file_get_contents(https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=UC40vLh6NqMw_F-QINO-keJg&maxResults=10&key=AIzaSyDLrY): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in C:\xampp\htdocs\channels\index.php on line 9

Notice: Trying to get property 'items' of non-object in C:\xampp\htdocs\channels\index.php on line 31