如何用spotifyapi认证本地主机?

2024-04-24 12:31:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用spotifywebapi,并尝试使用Javascript和HTML创建一个新的Spotify播放器。你知道吗

但是,实例初始化失败。你知道吗

经过一些研究,我发现这很可能是因为我在本地主机上运行python服务器,并使用flask呈现html,因此Spotify拒绝了请求。当我在Chrome中运行HTML时,它就工作了。你知道吗

如果我在Spotify开发者面板上创建了一个应用程序,是否有一些代码行可以用来以某种方式验证我的服务器?你知道吗

var workingToken = 'BQDThKGtGDKvFScIZ_JNRkU2WtdcazwLJpvMtXxw2G50l2OmX9iixB56pcdRArSsQvC1AK8yysyIYxDCQoCVNJuNd3fR_f_zDmDs1oUxFsTP64oKuG-dnMFO6qQlj23m81ZZAQgBQZ-l1NXG42IGf_AIsMUBP41v8MtR5ul8-VF81RM2lq35aN1nCElJtbk6or7kb7An59PaNmmR1wfDVS1wAMwX6unmaTE9CbBLB6wToII2by_msxC5zw4ewe3TlHuECD4cvlmIUtYY3Kh-dZc28nIASQ';
window.onSpotifyWebPlaybackSDKReady = () => {
    const token = workingToken;
    const player = new Spotify.Player({
        name: 'Web Playback SDK Quick Start Player',
        getOAuthToken: cb => { cb(token); }
        });

        // Error handling
        player.addListener('initialization_error', ({ message }) => { console.error(message); });
        player.addListener('authentication_error', ({ message }) => { console.error(message); });
        player.addListener('account_error', ({ message }) => { console.error(message); });
        player.addListener('playback_error', ({ message }) => { console.error(message); });

        // Playback status updates
        player.addListener('player_state_changed', state => { console.log(state); });

        // Ready
        player.addListener('ready', ({ device_id }) => {
            console.log('Ready with Device ID', device_id);
        });

        // Not Ready
        player.addListener('not_ready', ({ device_id }) => {
            console.log('Device ID has gone offline', device_id);
        });

        // Connect to the player!
        player.connect();
};

Tags: 服务器logidmessagedevicehtmlerrorspotify