Status Code 403 from Spotify API When Requesting User's Top Tracks and Top Artists

*Update I can query the artists node by providing their ID I only get 403 when querying the /me endpoint*

Working on a react application that allows a user to log in to Spotify and then displays their top 10 tracks and top 10 artists.

 

I can login with no problem, but when I request a users top tracks and artists I get this response from the API:

 

Failed to load resource: the server responded with a status of 403 ()

 

The account has been added to my Spotify dashboard, which I thought was the issue at first.

 

I've also tried writing the request with axios.get() and fetch(), both had the same status code.

 

Is there something wrong with my authorization flow? Or is the request improperly formatted?

 

My App.js and LogButton.js files which contain the authorization and request flows are attached

 

TYIA! Any help is greatly appreciated

Child Item
Child Item
Child Item

Accepted answers

I was missing the scope param on my authorize request. Scope defines what actions I'd like to be able to perform on behalf of the user. 

Here's an example: 

const SCOPE = 'user-read-private user-read-email user-read-playback-state user-modify-playback-state user-read-recently-played user-top-read';

Happy coding!

All comments

I don't know what's wrong with your code.

But, because your client secret is in the code you've shared, I recommend you to reset it. (And change the old one in your code for the new one.)

Thank you! Just realized I made a copy before I removed those whoops.

 

I was missing the scope param on my authorize request. Scope defines what actions I'd like to be able to perform on behalf of the user. 

Here's an example: 

const SCOPE = 'user-read-private user-read-email user-read-playback-state user-modify-playback-state user-read-recently-played user-top-read';

Happy coding!
Child Item
Child Item