Youtube API 在 Phonegap 中被屏蔽
Youtube API blocked in Phonegap
我尝试使用 Youtube API v3 在 cordova/phonegap 应用程序中加载 Youtube 视频,但应用程序一直说 API 未加载。
尽管它在 PhoneGap 开发应用程序内部运行,所以它看起来像是配置问题或其他问题。
config.xml 应该已授予对 API 的访问权限:
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
<plugin name="cordova-plugin-whitelist" spec="~1.3.3" />
并且 index.html 包含安全元标记:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' ajax.googleapis.com apis.google.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
以及js代码:
var checkYT = setInterval(function () {
if(YT.loaded){
clearInterval(checkYT);
}
}, 100);
window.onYouTubeIframeAPIReady = function () {
};
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
我也尝试了 JonSmart 的插件 CordovaYoutubeVideoPlayer,但没有任何运气:(
我不想要 iframe,因为我想保留自己对视频的控制权。
已解决!
index.html 应包含此安全行:
<meta http-equiv="Content-Security-Policy" content="default-src * data: blob: 'unsafe-inline' 'unsafe-eval'">
我尝试使用 Youtube API v3 在 cordova/phonegap 应用程序中加载 Youtube 视频,但应用程序一直说 API 未加载。 尽管它在 PhoneGap 开发应用程序内部运行,所以它看起来像是配置问题或其他问题。
config.xml 应该已授予对 API 的访问权限:
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
<plugin name="cordova-plugin-whitelist" spec="~1.3.3" />
并且 index.html 包含安全元标记:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' ajax.googleapis.com apis.google.com; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
以及js代码:
var checkYT = setInterval(function () {
if(YT.loaded){
clearInterval(checkYT);
}
}, 100);
window.onYouTubeIframeAPIReady = function () {
};
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
我也尝试了 JonSmart 的插件 CordovaYoutubeVideoPlayer,但没有任何运气:(
我不想要 iframe,因为我想保留自己对视频的控制权。
已解决!
index.html 应包含此安全行:
<meta http-equiv="Content-Security-Policy" content="default-src * data: blob: 'unsafe-inline' 'unsafe-eval'">