zmb3 / spotify

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

request requires user authentication #178

Closed dozheiny closed 2 years ago

dozheiny commented 2 years ago

Hello. I had a problem. I'm writing a bot that takes the name of the music and the artist and adds it to the selected playlist. Everything works except add music section to the playlist; the bot gives me this error: this request requires user authentication. but Spotify token and Spotify secret are valid.

I searched, but I didn't get anything. Is there anything more needed than Spotify Token and Spotify Secret? what should I do?

strideynet commented 2 years ago

Do you have a short code snipper that reproduces the issue ?

dozheiny commented 2 years ago

yeah

// create spotify client connection and context to connect spotify
    client, ctx := api.SpotifyConnection(SPOTIFYTOKEN, SPOTIFYSECRET)

    // add playlist
    playlist, err := client.GetPlaylist(ctx, PLAYLISTID)
    if err != nil {
        log.Fatal(err.Error())
    }

/* SOME CODES */

if results.Tracks != nil {
            items := results.Tracks.Tracks
            musicID := items[0].ID.String()
            cmd.AddMusic(client, ctx, playlist.ID.String(), musicID)
strideynet commented 2 years ago

Ah I see, are you authenticating as a user or just as an application ? To be able to add stuff to playlists I believe you need to authenticate as a user via oauth

dozheiny commented 2 years ago

oh yes, you right thanks , really