Phonegap中阻止了YouTube API

时间:2019-05-03 07:48:37

标签: cordova youtube-api 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,因为我想保留自己的视频控件。

1 个答案:

答案 0 :(得分:0)

解决了!

index.html应包含此安全线:

<meta http-equiv="Content-Security-Policy" content="default-src *  data: blob: 'unsafe-inline' 'unsafe-eval'">