I’m working on integrating Spotify’s Web API with my Qt application using QOAuth2AuthorizationCodeFlow but running into authentication issues.
I’ve set up my application credentials correctly:
Added my Client ID from Spotify app dashboard
Configured the Client Secret properly
Registered my app with Spotify
The main problem is with the redirect URI configuration. No matter what I set in my Spotify app settings, the OAuth flow keeps trying to use redirect_uri=http://localhost:8080 in the authorization URL. When I attempt to change it to HTTPS (https://localhost:8080), I get an “INVALID_CLIENT: Invalid redirect URI” error in the browser.
I tried programmatically setting the redirect URI using:
But this didn’t resolve the issue either. The login page does appear after clearing browser cache, but after entering credentials, the application doesn’t receive the authorization callback properly.
Has anyone successfully implemented Spotify OAuth2 with Qt? Do I need a premium Spotify account for API access? Any guidance on proper redirect URI configuration would be helpful.
spotify’s oauth is tricky but totally doable. the setProperty() method won’t work here - you’ve got to set up the redirect uri directly through the reply handler. create your qoauthhttpserverreplyhandler first, call setCallbackPath("/") on it, then assign it to your oauth flow. make sure your spotify dashboard has the exact same uri, including port number. if you’ve been testing a bunch, try clearing qt’s network cache - that sometimes fixes weird issues.
Had the same Spotify OAuth headache with Qt last year. Spotify’s redirect URI validation is brutal - everything has to match exactly, including trailing slashes and protocols. Don’t mess with HTTPS, just stick with HTTP on localhost since that’s what QOAuth2AuthorizationCodeFlow uses by default. In your Spotify dashboard, add http://localhost:8080 with no trailing slash if that’s what Qt’s sending. What saved me was using QNetworkAccessManager to peek at the actual authorization URL - log it so you can see exactly what redirect_uri parameter gets sent. Make sure you’ve got QOAuthHttpServerReplyHandler set up before calling grant(). The callback timing’s finicky, so throw some debug output in your reply handler to confirm it’s catching the response. You don’t need premium for basic API stuff.
Yeah, redirect URI mismatches are super annoying with Spotify’s OAuth. You don’t need premium for API access, but the redirect URI has to match exactly. Check your Spotify app settings and add the exact URI Qt’s using. If Qt defaults to http://localhost:8080, that’s what goes in your dashboard - don’t mess with HTTPS on localhost unless you’ve got SSL certs set up. I had way better luck calling setReplyHandler() before starting the grant flow. Also make sure your QOAuthHttpServerReplyHandler is listening on the same port as your redirect URI. Sometimes port binding fails quietly and your callback never makes it to the app. And if you’re still testing, double-check your Spotify app is in “Development” mode - that affects which redirect URIs work.