Announcements

Help Wizard

Step 1

NEXT STEP

getMyTopTracks not working

Solved!

getMyTopTracks not working

I have been trying to get my top tracks using this in Typescript:

async getDefault2(){
let tracks = await this.authService.getApi().getMyTopTracks({
time_range: "medium_term",
});
console.log(tracks)
}

The strange part is that the only method that is actually working is getMe() and I don't know why! I always get a 403 error!

Reply

Accepted Solutions
Marked as solution

You are missing the user-top-read Scope.

(I assume you have Authorization implemented.)

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

View solution in original post

6 Replies

Can you please post code of how you get an Access Token?

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

First the login:

window.location.href = `https://accounts.spotify.com/authorize?client_id=${client_id}&redirect_uri=${redirect_uri}&response_type=token&show_dialog=true`;

Then when I get redirected, I get the token like this:

const token = this.route.snapshot.fragment.split('&')
.find(fragment => fragment.includes('access_token'))
.split('=')[1];

this.spotifyApi.setAccessToken(token);

I am using 'spotify-web-api-js' library.

Marked as solution

You are missing the user-top-read Scope.

(I assume you have Authorization implemented.)

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Thanks, that just worked fine!

i already added that scope but still not working 

@oozkanneray are you using an Authorization method other than Client Credentials? Because with that method, it won't work.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 4 years ago  in Social & Random