2017-06-07 5 views
0
var SpotifyWebApi = require('spotify-web-api-node'); 

var spotifyApi = new SpotifyWebApi({ 
    clientId : 'xxx', 
    clientSecret : 'xxx', 
    redirectUri : 'https://example.com/callback' 
}); 

spotifyApi.getTrack('2q8eudK0r9ImgCB1XhFfxG').then(function(data) { 
    console.log(data); 
}); 

私のコードは機能しましたが、1ヶ月間このエラーがあります。spotify-web-api-node - WebapiError:Unauthorized

(node:12824) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): WebapiError: Unauthorized

(node:12824) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

+0

は私が既に持っているここhttps://github.com/thelinmichael/spotify-web-api-node/issues/86 – Victor

+0

を見てみましょうクライアントIDを再生成し、秘密のID ... –

答えて

0

this issueによれば、アクセストークンを設定する必要があります。

spotifyApi.setAccessToken('myAccessToken'); 

また、ここで見てみましょう:https://github.com/thelinmichael/spotify-web-api-node#setting-credentials

// Set necessary parts of the credentials on the constructor 
var spotifyApi = new SpotifyWebApi({ 
    clientId : 'myClientId', 
    clientSecret : 'myClientSecret' 
}); 

// Get an access token and 'save' it using a setter 
spotifyApi.clientCredentialsGrant() 
    .then(function(data) { 
    console.log('The access token is ' + data.body['access_token']); 
    spotifyApi.setAccessToken(data.body['access_token']); 
    }, function(err) { 
    console.log('Something went wrong!', err); 
    }); 

// Get tracks in a playlist 
spotifyApi.getPlaylistTracks('thelinmichael', '3ktAYNcRHpazJ9qecm3ptn', { 'offset' : 1, 'limit' : 5, 'fields' : 'items' }) 
    .then(function(data) { 
    console.log('The playlist contains these tracks', data.body); 
    }, function(err) { 
    console.log('Something went wrong!', err); 
    }); 
+0

ありがとう!私はその間に解決策を見つけました。 –