Bad request
See original GitHub issueHi there,
I’m trying to make a request, but I really don’t get what I’m doing wrong, error messages like shown below keep showing up:
Something went wrong on auth! { [WebapiError: Bad Request] name: 'WebapiError', message: 'Bad Request', statusCode: 400 }
and
Something went wrong on playlists! { [WebapiError: Unauthorized] name: 'WebapiError', message: 'Unauthorized', statusCode: 401 }
This afternoon I got it working once, but now the access token is expired or something I guess? But when I’ll run the refresh function you posted in the authorization section I’ll get:
Could not refresh access token { [WebapiError: Bad Request] name: 'WebapiError', message: 'Bad Request', statusCode: 400 }
How can I debug this? What can I do? If it helps, here is my SpotifyClient class:
import SpotifyWebApi from 'spotify-web-api-node';
class SpotifyClient {
constructor(username) {
this.username = username;
this.spotifyApi = new SpotifyWebApi({
clientId : 'CLIENT_ID',
clientSecret : 'CLIENT_SECRET',
redirectUri : 'http://localhost:6001/cv',
accessToken : 'HERE_WAS_THE_CODE'
});
// this.setAuthorization();
this.refreshAuthorization();
}
setAuthorization() {
const scopes = ['user-read-private', 'user-read-email'];
const state = 't3st';
const authorizeURL = this.spotifyApi.createAuthorizeURL(scopes, state);
console.log(authorizeURL);
const code = 'HERE_WAS_THE_CODE_FROM_AUTH_URL';
this.spotifyApi.authorizationCodeGrant(code)
.then(function(data) {
console.log('The token expires in ' + data.body['expires_in']);
console.log('The access token is ' + data.body['access_token']);
console.log('The refresh token is ' + data.body['refresh_token']);
// Set the access token on the API object to use it in later calls
this.spotifyApi.setAccessToken(data.body['access_token']);
this.spotifyApi.setRefreshToken(data.body['refresh_token']);
}, function(err) {
console.log('Something went wrong on auth!', err);
});
}
refreshAuthorization() {
this.spotifyApi.refreshAccessToken()
.then(function(data) {
console.log('The access token has been refreshed!');
// Save the access token so that it's used in future calls
this.spotifyApi.setAccessToken(data.body['access_token']);
}, function(err) {
console.log('Could not refresh access token', err);
});
}
getPlaylistById(callback) {
console.info('spotify client get');
this.spotifyApi.getPlaylist(this.username, '2tj5TA5I1QySyHI3YdpXYj')
.then(function(data) {
// console.log('Some information about this playlist', data.body);
console.info('spotify client did return');
// return data.body;
callback(null, data.body);
}, function(err) {
console.log('Something went wrong on playlists!', err);
});
}
}
export default SpotifyClient;
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:13
Top GitHub Comments
@tetreault No problem. We’ve all been there… several times a week. Computer is a weird science. Sometimes I would like to go and grow potatoes instead.
I had the same problem.
I couldn’t solve it within this wrapper. Now i use https://github.com/jaredhanson/passport-github to authenticate. If you want some sample code feel free to contact me.