Skip to content
Advertisement

Extract token from response url – Spotify API

I’m using this code to get a token from Spotify’s Web API:

JavaScript

That results in this showing up in the browser:

JavaScript

Great! But how do I extract “{token}” from the response and use it as a parameter in a request to the API? For example in the request to https://api.spotify.com/v1/users/{user_id}/playlists which needs the token in the header field.

Thanks!

Advertisement

Answer

You need to decode the JSON:

JavaScript

Then you’ll have an array with the values.

JavaScript

Also, you’re missing a necessary option to obtain the response in this way:

JavaScript

If not defined, you will get a boolean value instead of the response.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement