4
final AuthenticationRequest request = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI)
            .setScopes(new String[]{"playlist-read"})
            .build();

AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);

The above is the code that is run once the login button is clicked. This code works fine when run on an emulator. Below is the onActivityResult:

if (requestCode == REQUEST_CODE) {
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
        switch (response.getType()) {
            // Response was successful and contains auth token
            case TOKEN:
                logMessage("Got token: " + response.getAccessToken());
                CredentialsHandler.setToken(this, response.getAccessToken(), response.getExpiresIn(), TimeUnit.SECONDS);
                startMainActivity(response.getAccessToken());
                break;

            // Auth flow returned an error
            case ERROR:
                logError("Auth error: " + response.getError());
                break;

            // Most likely auth flow was cancelled
            default:
                logError("Auth result: " + response.getType());
        }
    }

When the app is run on a device that HAS the Spotify App installed, response.getType() returns ERROR with response.getError() being INVALID_APP_ID.

My app's package name and SHA-1 fingerprint is entered in the dev portal in Spotify, and that shouldn't be the problem since it works on an emulator. Why isn't the token being sent in the response? Thanks in advance!

PS: To clarify, this is NOT a duplicate of Spotify API: INVALID_APP_ID

The post's answer is to put the SHA-1 fingerprint and package name in the portal, but I have already done that.

Community
  • 1
  • 1
darkterbears
  • 169
  • 12
  • Possible duplicate of [Spotify API: INVALID\_APP\_ID](https://stackoverflow.com/questions/34908193/spotify-api-invalid-app-id) – Martin Zeitler Aug 31 '18 at 17:33
  • 1
    often see this, that people pretend it would be "no duplicate", in order to justify a duplicate question; while most likely just not having added either the proper (or both) of the `SHA-1` key fingerprints. – Martin Zeitler Aug 31 '18 at 17:34

1 Answers1

2

You should add both (debug and release) SHA1 fingerprints and packagename in your project settings on https://developer.spotify.com/dashboard/.

See https://developers.google.com/android/guides/client-auth for help how to get the SHA1.

Stefan
  • 352
  • 2
  • 17