我想用 YouTube 数据 API v3 在我自己的网站上显示 youtube 频道直播

I want to show youtube channel live broadcast on my own website with YouTube Data API v3

我有一个纯 HTML 网站,当我在 YouTube 上直播时,我想在其中显示我频道的 YouTube 直播。

$.ajax({
    url: "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2C+snippet%2C+contentDetails&broadcastType=all&mine=true&key={my-key}",
    type: "GET",
    success: function (result) {
        console.log(result);
    }
});

当我使用上面的代码时,它显示我需要登录。

有什么方法可以在不登录的情况下显示我的频道直播视频吗?

$.ajax({
    type: "GET",
    url: "https://www.googleapis.com/youtube/v3/search?part=id,snippet&eventType=completed&channelId={YOUR-CHANNEL-ID}&type=video&key={YOUR-API-KEY}",
   
    async:true,
    crossDomain:true,
    dataType : 'JSON',
    success: function(data){
  $.each(data.items,
            function(i,item)
            { 
    var app = 
    '<div>\
       <iframe src="https://www.youtube.com/embed/'+item.id.videoId+'" width="100%" height="auto" allowfullscreen></iframe>\
      </div>';
                $('.container').append(app);
        }); 
    }
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
 
</div>
我找到了一个没有 OAUTH2.0 使用 API KEY 和 channel-ID 使用 search API of YT DATA API 的解决方法。 您可以将 eventType 更改为 livecompleteditems.snippet.id.videoId 用于视频 ID,items.snippet.title 用于视频标题。 阅读文档 https://developers.google.com/youtube/v3/docs/search/list

您将需要使用 Oauth2 身份验证 API 它出现。

https://developers.google.com/youtube/v3/live/registering_an_application

The page allows you to create two different types of credentials. However, all of the methods for the YouTube Live Streaming API require OAuth 2.0 authorization. Follow the instructions below to generate OAuth 2.0 credentials.

OAuth 2.0: Your application must send an OAuth 2.0 token with any request that accesses private user data. Your application sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.

See the Creating OAuth 2.0 credentials section for more information.

API keys: You have the option of including an API key with a request. The key identifies your project and provides API access, quota, and reports.

Note that all of the methods for the YouTube Live Streaming API require OAuth 2.0 authorization. For that reason, you need to follow the instructions above for generating OAuth 2.0 credentials. If you want, you can also send an API key, but it is not necessary.