Youtube API V3 存在 YouTube URL 中包含特殊字符的问题

问题描述 投票:0回答:1

我是这个 YouTube API 的新手。 我尝试使用不同类型的 YouTube 网址,但唯一困扰我的是包含特殊字符(/、_ 等)的网址,例如 -

https://www.youtube.com/watch?v=kXYiU_JCYtU

当我尝试将此网址嵌入 iFrame 时,出现此问题。

error image

这是我从谷歌获取的嵌入代码,用于在页面中显示它

<iframe src="https://www.youtube.com/embed/kXYiU_JCYtU" title="CASTLE OF GLASS [Official Music Video] - Linkin Park" allow='autoplay'> </iframe>

我尝试添加一些 iFrame 属性,但仍然没有成功。

<iframe src='https://www.youtube.com/embed/kXYiU_JCYtU' title='CASTLE OF GLASS [Official Music Video] - Linkin Park' allow='autoplay; encrypted-media' referrerpolicy="no-referrer-when-downgrade" sandbox="allow-same-origin allow-scripts" rel="noopener external"> </iframe>

最后我尝试了 Youtube iFrame api 但结果仍然相同。 Youtube iFrame API error img

我只想让 iFrame 显示视频,就像它们在 youtube 中可见一样。

html youtube-api youtube-data-api
1个回答
0
投票

我使用我自己的包含下划线字符的视频 ID 测试了您的 iframe 语法。效果很好。一定还有其他原因导致您出现此问题。

您的视频是否启用了嵌入? 请参阅https://support.google.com/youtube/answer/171780

如果这不是问题,请查找与使用 YouTube“嵌入”URL 正确播放的其他视频相比可能不同的任何其他设置。

顺便说一句...使用 YouTube“嵌入”URL 与使用 YouTube API 不同。 YouTube API 是一个应用程序编程接口 - 一组软件开发人员使用的库。请参阅 https://developers.google.com/youtube

© www.soinside.com 2019 - 2024. All rights reserved.