Skip to content

Authentication Service Unknown Error, login not taking place #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AdvaitChirmule opened this issue Jun 17, 2024 · 1 comment
Open

Comments

@AdvaitChirmule
Copy link

Thanks for your interest in the Spotify App Remote SDK!
If you're submitting a bug, please use the following template.
If your issue is a feature request, please include your use-case so that we have all the necessary info.

Issue found on June 16, 2024.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        authenticateSpotify();
    }

    private void authenticateSpotify() {
        AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(CLIENT_ID, AuthorizationResponse.Type.CODE, REDIRECT_URI);
        builder.setScopes(new String[]{"streaming"});
        AuthorizationRequest request = builder.build();
        AuthorizationClient.openLoginActivity(this, 1337, request);
    }

    @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 == 1337) {
            AuthorizationResponse response = AuthorizationClient.getResponse(resultCode, intent);
            switch (response.getType()) {
                // Response was successful and contains auth token
                case CODE:
                    Toast.makeText(MainActivity.this, "Here", Toast.LENGTH_SHORT).show();
                    connectToSpotifyRemote();
                    break;

                // Auth flow returned an error
                case ERROR:
                    Toast.makeText(MainActivity.this, "Authorization error: " + response.getError() + response.getCode(), Toast.LENGTH_SHORT).show();
                    break;

                // Most likely auth flow was cancelled
                default:
                    // Handle other cases
            }
        }
    }

    private void connectToSpotifyRemote() {
        ConnectionParams connectionParams = new ConnectionParams.Builder(CLIENT_ID)
                .setRedirectUri(REDIRECT_URI)
                .showAuthView(true)
                .build();

        SpotifyAppRemote.connect(this, connectionParams, new Connector.ConnectionListener() {

            public void onConnected(SpotifyAppRemote spotifyAppRemote) {
                mSpotifyAppRemote = spotifyAppRemote;
                Log.d("MainActivity", "Connected! Yay!");
                Toast.makeText(MainActivity.this, "Connected to Spotify Remote", Toast.LENGTH_SHORT).show();
                // Now you can start interacting with App Remote
                connected();
            }

            public void onFailure(Throwable throwable) {
                Toast.makeText(MainActivity.this, "Failed to connect to Spotify Remote", Toast.LENGTH_SHORT).show();
                Log.e("MainActivity", throwable.getMessage(), throwable);
                // Something went wrong when attempting to connect! Handle errors here
            }
        });

My Client ID is correct, I have used the same Redirect URI in both my dashboard and my code, I have added the SHA1 key but I just don't seem to get it authorized.

It fails at this line: AuthorizationResponse response = AuthorizationClient.getResponse(resultCode, intent); Spotify app seems to open up for a split second (cause I see the loading sign) before getting the AUTHORIZATION SERVICE UNKNOWN error. I have the app and I have logged in using the same ID. Tried on a virtual device and also my personal phone but both of them did not work. Could someone please help? I didn't find anything on the internet so I'm not sure what the issue is.

@Luytenn
Copy link

Luytenn commented Sep 8, 2024

I'm having the same problem, did you found any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants