zmb3 / spotify

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

can't create a new client... What am i doing wrong? #208

Open JulietteDestang opened 1 year ago

JulietteDestang commented 1 year ago

hi guys, thanks for this package!

i'm trying to create an oAuth for spotify, but i have an "infinite loop" in the callback

func AuthSpotify(w http.ResponseWriter, r *http.Request) {
    tok, err := auth.Token(r.Context(), state, r)
    if err != nil {
        http.Error(w, "Couldn't get token", http.StatusForbidden)
        log.Fatal(err)
    }
    if st := r.FormValue("state"); st != state {
        http.NotFound(w, r)
        log.Fatalf("State mismatch: %s != %s\n", st, state)
    }

    client := spotify.New(auth.Client(r.Context(), tok))
    // infinite loop ^^^

    w.Header().Set("Content-Type", "text/html")
    fmt.Fprintf(w, "Login Completed!")
    ch <- client
}

i send the url to my front with this function:

func GetSpotifyUrl(w http.ResponseWriter, r *http.Request) {
    fmt.Println("ok")
    url := auth.AuthURL(state)
    res, _ := json.Marshal(url)
    w.WriteHeader(http.StatusOK)
    w.Write(res)

}

the redirect is working and call my callback, but i'm stuck in this callback function :/

can you help me? thanks a lot!