question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Receiving 400 error with authorizationCodeGrant

See original GitHub issue

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.

spotifyApi.authorizationCodeGrant(code)
  		   .then(function(data) {
	    	          spotifyApi.setAccessToken(data.body['access_token']);
	    	          spotifyApi.setRefreshToken(data.body['refresh_token']);
	    	          spotifyApi.createPlaylist(userObj['id'], playlistName, { public : false })
	    	              .then(function(data) {
	    	                  sendTextMessage(sender, "success! created playlist: " + JSON.stringify(data.body))
	    	              }, function(err) {
	    	                         console.log('Something went wrong createPlaylist!', err);
	    	             });
  		   }, function(err) {
    	                   console.log('Something went wrong authorizationCodeGrant!', err);
});

Any help is appreciated, thank you!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:13

github_iconTop GitHub Comments

1reaction
Nase00commented, Apr 19, 2017

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
0reactions
brunano21commented, May 19, 2020

do I have to generate an authorizationCcode every time I run my script?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting status code 400 (Bad Request error) from ... - MSDN
Well, i getting error 400 (Bad request) as result of executing this step 5 of Authorization code grant flow from here: ...
Read more >
Get Access Token Bad Request Exception for OAuth With ...
I can get the code but when get access token by code, it throws error 400. ... Bad Request Exception for OAuth With...
Read more >
AuthorizationCodeGrant HttpResponseException: 400 Bad ...
HttpResponseException: 400 Bad Request' error. trying to get the accessTokenResponse. Any idea why ? AuthorizationCodeGrant request = new ...
Read more >
bad request in authorization code flow - AWS re:Post
I am about to exchange authorization code for access token but get bad request/400 error: "invalid_request" all the t...
Read more >
Generic OAuth2 - 400 Error - Questions - n8n community
Hello there, I am trying to setup a generic OAuth Integration - it is working until the last step. I authenticate the service...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found