zmb3 / spotify

A Go wrapper for the Spotify Web API
Apache License 2.0
1.33k stars 284 forks source link

ScopeUserTopRead & ScopeUserFollowRead Incompatible? #207

Closed TimHi closed 1 year ago

TimHi commented 1 year ago

I'm running into an issue when using ScopeUserTopRead and ScopeUserFollowRead together.

I've checked the scopes reference to see if there is some kind of mutual exclusiveness between the two scopes but it doesnt seem like it.

My authentication is built like this:

var (
    auth  = spotifyauth.New(spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), spotifyauth.WithScopes(spotifyauth.ScopeUserTopRead), spotifyauth.WithScopes(spotifyauth.ScopeUserFollowRead), spotifyauth.WithClientID("CLIENTID"), spotifyauth.WithClientSecret("SECRET"))
    ch    = make(chan *spotify.Client)
    state = "abc123"
)

The CurrentUsersFollowedArtists endpoint works fine, but the CurrentUsersTopArtists/CurrentUsersTopTracks are returning errors:

Get user top items spotify: HTTP 403: Forbidden (body empty)

If I remove the spotifyauth.WithScopes(spotifyauth.ScopeUserFollowRead) and build my auth like this:

var (
    auth  = spotifyauth.New(spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), spotifyauth.WithScopes(spotifyauth.ScopeUserTopRead), spotifyauth.WithClientID("CLIENTID"), spotifyauth.WithClientSecret("SECRET"))
    ch    = make(chan *spotify.Client)
    state = "abc123"
)

I'm receiving valid responses from the CurrentUsersTopArtists/CurrentUsersTopTracks endpoints. (CurrentUsersFollowedArtists doesnt work anymore since the scope is missing).

Am I doing something wrong in building the scopes?

Edit:

I just tried moving positions of the scopes, resulting in an insufficient scope error:

auth  = spotifyauth.New(spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes(spotifyauth.ScopeUserFollowRead), spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), spotifyauth.WithScopes(spotifyauth.ScopeUserTopRead), spotifyauth.WithClientID("CLIENTID"), spotifyauth.WithClientSecret("SECRET"))

2022/10/27 09:48:29 Insufficient client scope

TimHi commented 1 year ago

Issue on my side, after checking the implementation of WithScopes I saw my error. This works now:

var (
    auth  = spotifyauth.New(spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes(spotifyauth.ScopeUserFollowRead, spotifyauth.ScopeUserReadPrivate, spotifyauth.ScopeUserTopRead), spotifyauth.WithClientID("CLIENTID"), spotifyauth.WithClientSecret("SECRET"))
    ch    = make(chan *spotify.Client)
    state = "abc123"
)