什么" WebapiError"意思?

时间:2017-06-01 23:31:26

标签: javascript node.js reactjs spotify

我正在使用Spotify Web App,它只是检索KD Rusha热门专辑,试图使用客户端ID,艺术家ID仅在他的Spotify上获取KD Rusha热门专辑。我正在使用名为spotify-web-api-node的npm包。

错误讯息enter image description here

import React from 'react';
import SpotifyWebApi from 'spotify-web-api-node';
require('dotenv').config();

// My Steps: //
// GO TO SPOTIFY AND GETTING KD RUSHA TOP ABLUMS lIMIT TO 9 SONGS
// WHEN YOU CLICK ON TOP OF THE ABLUMS A PLAY BUTTON ICON WILL SHOW TO INDICATE THAT YOU CAN PLAY 30 SECONDS OF SONG

const spotifyApi = new SpotifyWebApi({
  clientId : 'here where client id',
  clientSecret : 'here where client secret',
  redirectUri : 'http://www.localhost.com/callback'
});

export default class SpotifyComponent extends React.Component {

  componentDidMount() {
    window.setTimeout(() => {
      this.fetchData();
    }, 3000)
  }

 fetchData() {//Its Fetch Artist Albums The Spotify Date
   spotifyApi.getArtistAlbums('5JLWikpo5DFPqvIRi43v5y', {limit: 9})
     .then(function(data) {
       return data.body.albums.map(function(a) { return a.id; });
     })
     .then(function(albums) {
       return spotifyApi.getAlbums(albums);
     }).then(function(data) {
       console.log(data.body);
   });
 }

  render(){
    return(
      <div className='spoify-container'>
        <img src="{image.albums}" alt="kdrusha-albums" />
      </div>
    );
  }
}

2 个答案:

答案 0 :(得分:0)

您回来的statusCode是401 Unauthorized,这意味着凭据存在问题。确保您正确初始化clientIdclientSecret

答案 1 :(得分:0)

您获得了401未经授权的错误。使用API​​进行身份验证的方式肯定有问题。根据Spotify的文档:https://developer.spotify.com/web-api/user-guide/#response-status-codes

401 Unauthorized - 请求需要用户身份验证,或者,如果请求包含授权凭据,则拒绝授权这些凭据。

检查您的凭据。