Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spotify API: INVALID_APP_ID

I am currently working on an android app which is implementing the Spotify API. I have all of the code connecting my app to spotify using the tutorial and have been working on my app for sometime now. When I play a song through my app after authenticating the user, it works perfectly, that is on my emulator. When I switch it over to my phone it didn't work and gave me an INVALID_APP_ID error in the android response. When I uninstalled spotify off my phone and then tried to login to spotify through my app, I was then able to play music from my phone without any crashes. So my question is how do I fix that? Here is my code for authenticating a user:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);

        // Check if result comes from the correct activity
        if (requestCode == requestcode) {
            AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
            if (response.getType() == AuthenticationResponse.Type.TOKEN) {
                Config playerConfig = new Config(this, response.getAccessToken(), client_id);
                token = response.getAccessToken();
                Spotify.getPlayer(playerConfig, this, new Player.InitializationObserver() {
                    @Override
                    public void onInitialized(Player player) {
                        mPlayer = player;
                        mPlayer.addConnectionStateCallback(.this);
                        mPlayer.addPlayerNotificationCallback(.this);

                    }

                    @Override
                    public void onError(Throwable throwable) {
                        Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage());
                    }
                });
            }
        }
    }
like image 488
Rockyfish Avatar asked Jan 20 '16 18:01

Rockyfish


2 Answers

You need to go to your Spotify developer settings and update the

Android Packages

Providing your full package name i.e. com.company.app and the SHA1 fingerprint of the respective build variant.

You can get the fingerprint by running

./gradlew signingReport

There you can find the results for e.g. debug

Variant: debug
Config: debug
Store: /Users/<your username>/.android/debug.keystore
Alias: AndroidDebugKey
MD5:  00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
SHA1: 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00
Valid until: Monday, August 29, 2046

Saving the settings on your Spotify app page is enough to flush the system so that you can login from your device.

like image 98
Fhl Avatar answered Sep 21 '22 10:09

Fhl


The answers above were helpful. However, it was another issue that caught me out.

As part of it's release management process, the play store offers to manage release keys. If you enable this feature the SHA-1 certificate for the app is replaced before it is delivered to users. You need to make sure that the new key is also registered on the spotify developers console.

To view the new key, open the google play store developers dashboard, and then click 'Release management > App signing'. You should be able to view the key here.

like image 22
Phil Francis Avatar answered Sep 20 '22 10:09

Phil Francis