zmb3 / spotify

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

I keep getting "Missing required parameter: client_id" on authentication example #230

Closed percit closed 1 year ago

percit commented 1 year ago

Hi, so I am trying to get authentication example to work, but I keep getting "Missing required parameter: client_id". After manualy pasting my client ID from Spotify I just get "This site can’t be reachedlocalhost refused to connect.". My spotify redirectUri is set correctly, so I am not sure what to do more. Can anybody help me?

TimHi commented 1 year ago

I'm assuming you are trying to run authenticate.go. Are you sure the redirect url is set up correctly?

You need to register http://localhost:8080/callback as mentioned here. Also the missing client id is probably due to you not having the enviroment variable set as mentioned in the comment aswell.

percit commented 1 year ago

yeah, I do have redirect URI, and added client_id and client secret, like this: auth := spotifyauth.New( spotifyauth.WithClientID(SpotifyClientID), spotifyauth.WithClientSecret(SpotifyClientSecret), spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes( spotifyauth.ScopePlaylistModifyPublic, spotifyauth.ScopePlaylistModifyPrivate, ), ) and it parses client_id correctly now, but in URI that I got from app, I cannot find client secret, and I get "404 page not found"

TimHi commented 1 year ago

It's normal that the client secret is not part of the URL. That exchange will happen when the tokes are requested, see docs.

The redirectURI from spotifyauth.WithRedirectURL(redirectURI) is registered in your spotify app? From the authcode example it should look like this: image

If that is setup correctly the example should run just fine. Maybe you have external tools (firewall, proxy ..) that block the access of your localhost

percit commented 1 year ago

image yes, I have uri. And no, I don't have any problem with localhost, as I used it many times before in previous golang projects. Is there a chance that golang spotify api has a bug? Have you tried using this authenticate.go recently?

TimHi commented 1 year ago

Yes, running the authcode/authenticate.go example works without issues, I'm even using the scopes from your code:

...
// redirectURI is the OAuth redirect URI for the application.
// You must register an application at Spotify's developer portal
// and enter this value.
const redirectURI = "http://localhost:8080/callback"

var (
    auth = spotifyauth.New(spotifyauth.WithRedirectURL(redirectURI), spotifyauth.WithScopes(
        spotifyauth.ScopePlaylistModifyPublic,
        spotifyauth.ScopePlaylistModifyPrivate,
    ), spotifyauth.WithClientID("ClientID"), spotifyauth.WithClientSecret("ClientSecret"))
    ch    = make(chan *spotify.Client)
    state = "abc123"
)
...
PS go run .\authenticate.go
Please log in to Spotify by visiting the following page in your browser: https://accounts.spotify.com/authorize?client_id=ClientID&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fcallback&response_type=code&scope=playlist-modify-public+playlist-modify-private&state=abc123
You are logged in as: timhi
percit commented 1 year ago

I managed to make it work on bare example, thanks