一年前进行的作业分配在网站中嵌入了一部youtube电影。曾经工作过,现在出现403错误。该代码在我的计算机上是本地的,没有人使用它。所有其他API均有效。已启用API。条款已更新。我假设我必须接受适用的条款
已禁用和启用youtube API,请阅读条款。找不到我需要接受条款的地方。确认API没有流量
function getfavesong(favSong) {
var youtubeURL;
$.ajax({
//replace avemaria with favorite song submission from form
url: "https://www.googleapis.com/youtube/v3/search?part=snippet&q=" + favSong + "&key=AIzaSyDykB9j6toAsoXNLuQcM8lJw_Wck_jynPE",
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function (data) {
console.log(data);
console.log("youTube video ID: " + data.items[0].id.videoId);
youtubeURL = "https://www.youtube.com/embed/" + data.items[0].id.videoId;
console.log("youTube complete URL: " + youtubeURL);
//$("#faveVideo").attr("src",youtubeURL);
}).done(function () {
console.log("youTube complete URL: " + youtubeURL);
$("#faveVideo").attr("src", youtubeURL);
$('#song_title').text(favSong);
})`enter code here`
}
我希望显示嵌入在我的网站中的视频,而不是一个空白框。
答案 0 :(得分:0)
嵌入视频
1 On a computer, go to the YouTube video you want to embed.
2 Under the video, click SHARE Share.
3 Click Embed.
4 From the box that appears, copy the HTML code.
5 Paste the code into your blog or website HTML.
嵌入播放列表
1 Sign in to your YouTube account on a computer.
2 On the left side of the page, select the playlist you want to embed.
3 Copy the playlist ID from the URL.
4 Modify the embed code for an individual video by doing the following:
* In the place of the video ID (after "embed/"), substitute "videoseries?list=".
* Then paste the playlist ID after the "=".
* Paste the code into your blog or website HTML.
示例:
<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
参考链接:https://support.google.com/youtube/answer/171780?hl=en https://www.w3schools.com/html/html_youtube.asp
希望这可以为您提供帮助。