Open mdoxey06 opened 7 years ago
I have same problem too.
I was getting a similar error until I added redirectUri
to my SpotifyWebApi
instance. Like so:
const spotifyApi = new SpotifyWebApi({
clientId: '123',
clientSecret: 'abc',
redirectUri: 'https://example.com/callback'
});
spotifyApi.authorizationCodeGrant(code).then(doStuffWithData) // no more 400
@mdoxey06 did you manage to solve it?
I have found that when I put the spotifyApi.createPlaylist
call after the spotify.Api.authorizationCodeGrant
call (instead of nested inside the .then()
), it works for me.
@mdoxey06 but then createPlaylist
would run before setting the access token, wouldn't it?
The odd thing I'm finding when testing it now is that I receive a 400 on the first try, and then it tries again and successfully creates the playlist (after only running once). Would there be any reason for this?
Me too. Today works here.
@mdoxey06 AFAIK there is no code in the library to retry this. Do you mind sharing a code snippet?
@JMPerez Here is a code snippet from my project that is currently working:
// code stored from previous user login
spotifyApi.authorizationCodeGrant(code)
.then(function(data) {
spotifyApi.setAccessToken(data.body['access_token']);
spotifyApi.setRefreshToken(data.body['refresh_token']);
}, function(err) {
console.log('Something went wrong authorizationCodeGrant!', err);
});
spotifyApi.createPlaylist(userObj['id'], playlistName, { public : false })
.then(function(data) {
playlistId = data.body.id;
console.log(sender, "success! created playlist: " + JSON.stringify(data.body.id));
}, function(err) {
console.log('Something went wrong createPlaylist!', err);
});
I'd like to bump this as well - I am randomly getting failures here on a production app. Seems like this just fails randomly with a 400 bad request error.
Would also like to bump, still having issues with this.
Same here running into similar issues
do I have to generate an authorizationCcode every time I run my script?
Hi,
I'm trying to create a playlist (after the user logs in), but after trying to generate a new access_token using authorizationCodeGrant(), I get "{ [WebapiError: Bad Request] name: 'WebapiError', message: 'Bad Request', statusCode: 400 }". I am using the same code that is generated after the callback on user login.
Any help is appreciated, thank you!