zmb3 / spotify

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

GetShow() returns "non existing id" #187

Closed sa7mon closed 2 years ago

sa7mon commented 2 years ago

Here's my PoC code trying to fetch info about a show:

ctx := context.Background()
config := &clientcredentials.Config{
    ClientID:     os.Getenv("SPOTIFY_ID"),
    ClientSecret: os.Getenv("SPOTIFY_SECRET"),
    TokenURL:     spotifyauth.TokenURL,
}
token, err := config.Token(ctx)
if err != nil {
    log.Fatalf("couldn't get token: %v", err)
}

httpClient := spotifyauth.New().Client(ctx, token)
client := spotify.New(httpClient)

show, err := client.GetShow(ctx, "6kAsbP8pxwaU2kPibKTuHE")
if err != nil {
    log.Fatal(err)
}

j, err := json.Marshal(show)
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(j))

When I run it, I get the line "non existing id" logged after the GetShow() call. I know for sure this show exists, as you can navigate to it on the web here

Am I doing something wrong?

strideynet commented 2 years ago

So I can definitely query this via the API Console on the Spotify site, so it looks like it must be a bug in our library. I'll look to try and reproduce this soon.

strideynet commented 2 years ago

I've reproduced this as code, and found a work-around.

It looks like they require the market to be specified when fetching a show. e.g

    show, err := client.GetShow(ctx, "0azMejb7zrmAqctVsUSAdq", spotify.Market(spotify.CountryUnitedKingdom))
    if err != nil {
        log.Fatal(err)
    }

I can only hazard a guess that when a token linked to a user is used, they default to the market associated with the user, which is why the online API dashboard works fine.

I'll keep this issue open and add a godoc comment to note this behaviour.

sa7mon commented 2 years ago

Awesome, this totally fixes it! Thanks, I thought I was going to have to shell out to a Python library to do the auth which I really didn't want to do

JOY2OP commented 11 months ago

This worked for me too. THANKS. Spend a lot of time on this. Can you put this into your documentation?