0

基本上我正在尝试使用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)

}
4

1 回答 1

0

这是 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
于 2020-02-12T20:44:53.603 回答