Encountering auth_service_unavailable error while trying to authenticate with Spotify

I’m experiencing an issue when logging into Spotify within my Android application. Every time I try to log in through the Spotify app, it throws an AUTHENTICATION_SERVICE_UNAVAILABLE error. On the other hand, if the Spotify app gets uninstalled, logging in through the browser works smoothly. I would prefer users to log in directly via the Spotify app if it’s available on their device.

public void startSpotifyLogin(boolean attemptAgain) {
    this.attemptAgain = attemptAgain;
    AuthorizationRequest.Builder requestBuilder =
            new AuthorizationRequest.Builder(CLIENT_ID, AuthorizationResponse.Type.TOKEN, REDIRECT_URI);
    requestBuilder.setScopes(new String[]{"user-read-private", "streaming", "playlist-read-private", "user-library-read"});
    AuthorizationRequest authRequest = requestBuilder.build();

    AuthorizationClient.openLoginActivity(this, SPOTIFY_LOGIN_REQUEST_CODE, authRequest);
}

When the error occurs, the log details are:

2021-12-22 11:36:29.802 5069-5069/? I/com.spotify.sdk.android.auth.LoginActivity: Spotify auth completing. The response is in EXTRA with key 'response'
2021-12-22 11:36:29.822 5069-5069/? D/StartActivity: Spotify error: AUTHENTICATION_SERVICE_UNAVAILABLE

Has anyone faced this before? I would appreciate any insights!

I encountered a similar issue a while ago, and it often boils down to authorization token inconsistencies between your application and the Spotify app. The AUTHENTICATION_SERVICE_UNAVAILABLE error indicates a mismatch in the authentication process. To resolve this, I suggest implementing a fallback mechanism that switches to web-based authentication when native app attempts fail. Additionally, verify that your app has the necessary permissions enabled for Spotify in the device settings, as this can interfere with the communication required for authentication.

This happens when your app can’t talk to Spotify’s auth service through the installed app. I’ve hit this before - it’s usually version compatibility problems or corrupted auth tokens in the Spotify app. Clear Spotify’s cache and data, then restart both apps. If that doesn’t fix it, add a fallback that switches to web auth when native auth fails. Also make sure you’re using the latest Spotify Android Auth SDK - older versions had this exact bug on certain Android versions.