祖先違反了以下 Spotify 的內容安全



>基本上我正在尝试javascript将spotify iframe添加到我的html中,但是我不断收到此错误,并且每个链接都收到此错误

*Refused to display 'https://open.spotify.com/album/5yc5YwQjqcNvGiFsTM0aAT' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".*

然后我添加了

<meta http-equiv="Content-Security-Policy" content="child-src https://open.spotify.com/">

到标题,但仍然没有运气

    var SpotifyWebApi = require('spotify-web-api-node');
     function getSpotify(artist){
    var spotify = new SpotifyWebApi({
        clientId: 'xxxxxxxxxxx',
        clientSecret: 'xxxxxxxxxxxxxxx',
        redirectUri: 'http://www.example.com/callback'
    });
    spotify = new SpotifyWebApi({
    accessToken: 'xxxxxxxxxxxxxxxxxxxxxx'
    });
    const spotifyDiv = document.createElement("div")
    const result = document.getElementById("result");
    spotifyDiv.className="spotify";
    spotify.searchAlbums(`artist:${artist}`).then(
        (data)=> {
            console.log(data.body)
         data.body.albums.items.forEach((album) =>{
             const iframe = document.createElement("iframe");
             iframe.src=album.external_urls.spotify;
             iframe.height = 300;
             iframe.width =300;
             iframe.frameBorder =0;
             iframe.setAttribute("allowtransparency","true");
             iframe.setAttribute("allow","encrypted-media");
             spotifyDiv.appendChild(iframe)
             console.log(iframe)
          });

        }).catch((error)=>{
            console.log(error);
        })
    result.appendChild(spotifyDiv)
}
这是 Spotify

Web-API 的已知问题: Refused to display [playlist_link] in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'". #1052链接到 Spotify 问题

该问题已解决,可能的解决方案是确保您的 URL 在路径名中包含 /embed/ 前缀。

例如

https://open.spotify.com/embed/album/0ODLCdHBFVvKwJGeSfd1jy

https://open.spotify.com/album/0ODLCdHBFVvKwJGeSfd1jy

最新更新