Javascript Resact Node.js与Spotify web api无法获取播放列表信息
我正在使用React构建一个小型web应用程序,以学习使用Spotify API:并遵循本教程:。但我遇到了一个问题。我有这个功能:Javascript Resact Node.js与Spotify web api无法获取播放列表信息,javascript,node.js,reactjs,spotify,Javascript,Node.js,Reactjs,Spotify,我正在使用React构建一个小型web应用程序,以学习使用Spotify API:并遵循本教程:。但我遇到了一个问题。我有这个功能: getNowPlaying(){ spotifyApi.getMyCurrentPlaybackState() .then((response) => { console.log(response); this.setState({ nowPlaying: {
getNowPlaying(){
spotifyApi.getMyCurrentPlaybackState()
.then((response) => {
console.log(response);
this.setState({
nowPlaying: {
name: response.item.name,
albumArt: response.item.album.images[0].url
}
});
})
}
它正确地返回我当前正在听的内容。我还有这个:
getUserPlaylist(){
spotifyApi.getUserPlaylists('1242952295')
.then((response) => {
console.log("This is the name of the 5th item in the response object: ", response.items[5].name);
});
}
正确返回我个人资料中第五个播放列表的名称
但是,这两个函数都不会返回有关特定播放列表的正确信息:
getSlamsPlaylist(){
spotifyApi.getPlaylist('1mJN7wfIm6NGYqniPuEKpJ') //5ieJqeLJjjI8iJWaxeBLuK (from example)
.then((response) => {
console.log(response);
});
}
getSlamsPlaylistV2(){
spotifyApi.getPlaylist('1mJN7wfIm6NGYqniPuEKpJ') //5ieJqeLJjjI8iJWaxeBLuK (from example)
.then(function(data) {
console.log('Some information about this playlist', data.body);
}, function(err) {
console.log('Something went wrong!', err);
});
}
第一个简单地返回:“uncaughtexception:Object”,而第二个返回播放列表id无效,即使我尝试了几个正确的id。另外,在从“getUserPlaylist()”方法返回的数据中,我可以看到我使用的id是正确的
此外,这还会返回未定义的:
getUserPlaylistV2(){
spotifyApi.getUserPlaylists('1242952295')
.then(function(data) {
console.log('Some information about this playlist', data.body);
}, function(err) {
console.log('Something went wrong!', err);
});
}
我错过了什么使这项工作
Console.log getSlamsPlaylist()的结果:
未捕获异常:对象
Console.log getslamsplayliv2()的结果:
如果我需要的话,我可以提供更多的信息
GetUserPlayV2()的Console.log结果:
有关此播放列表的一些信息未定义如果我们看到console.log结果,肯定会有所帮助。我编辑了我希望有帮助的问题。
Something went wrong!
XMLHttpRequest { onreadystatechange: onreadystatechange(), readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, responseURL: "https://api.spotify.com/v1/users/7CoPUH1fJFKzcc7NAIv9XU/playlists/undefined", status: 404, statusText: "Not Found", responseType: "", response: "{\n \"error\" : {\n \"status\" : 404,\n \"message\" : \"Invalid playlist Id\"\n }\n}" }