zmb3 / spotify

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

Error getting current playing song: spotify: couldn't decode error: (46) [User not registered in the Developer Dashboard #232

Closed TAMILVIP007 closed 1 year ago

TAMILVIP007 commented 1 year ago

https://nekobin.com/lujicuxepe.go hey there this is my complete oauth flow code

i am getting user id from user and trying to generate token and storing it to reuse it and get user current played songs. what i am stuck at is this error

Error getting current playing song: spotify: couldn't decode error: (46) [User not registered in the Developer Dashboard

i don't know why am i getting this error. It works fine initially when user try to get current track after that it returns this error. does it mean i cant re use token of other user with my client creds? or is there any other way to reuse or store any info which could get user track in each req instead of making them login again and again

TimHi commented 1 year ago

Couple of things, you are only persisting and reusing the access token, if that is expired it will fail. As mention in #221 the library will handle the case with an expired token, but the library needs the refresh token for that.

Your actual error message here indicates that a not registered user is trying to use your app. This is not related to this framework.

As described in the dashboard documentation while you are in development mode with your spotify app you need to add the users manually.

TAMILVIP007 commented 1 year ago

how do i pass a refresh token?

TimHi commented 1 year ago

I'm doing something like this in my project:

func createSpotifyClient(accessToken, refreshToken string, expiry time.Time, ctx context.Context) *spotify.Client {
    token := createToken(accessToken, refreshToken)
    httpClient := spotifyauth.New().Client(ctx, token)
    return spotify.New(httpClient)
}

func createToken(accessToken, refreshToken string) *oauth2.Token {
    token := &oauth2.Token{
        AccessToken:  accessToken,
        RefreshToken: refreshToken,
        TokenType:    "Bearer",
    }
    return token
}

In your code you're already doing something similiar, just extend this: c, err := spotify.New(auth.Client(ctx.Background(), &oauth2.Token{AccessToken: token})).Token()

JunNishimura commented 1 year ago

@TAMILVIP007

Hi! I solved this issue in the PR #233.

TAMILVIP007 commented 1 year ago

thanks a lot