Announcements

Help Wizard

Step 1

NEXT STEP

Not Able to Authenticate When Spotify is Installed

Not Able to Authenticate When Spotify is Installed

Plan

Premium

Country

USA

 

Device

Pixel 3a Virtual Device (API 28)

Operating System

Android 9.0 Pie

 

My Question or Issue

I'm using the AuthenticationRequest and AuthenticationClient to connect a Spotify account to my app. I was testing with no issues:

- Launch app

- Login Activity started

- User could log in

- Correctly got the user's token and opened the main activity

 

To test an open in-app feature, I installed Spotify on the emulator and it could no longer get the user's token. It attempts to open the Login Activity then throws this error:

Verification of com.spotify.sdk.android.authentication.AuthenticationResponse com.spotify.sdk.android.authentication.AuthenticationResponse$Builder.build() took 117.386ms
D/com.spotify.sdk.android.authentication.LoginActivity: Error authenticating

 

Then, when attempting to read the response, it returns "AUTHENTICATION_SERVICE_UNAVAILBLE"

 

When I uninstall both my app and Spotify then reboot my app, I'm able to log in again. I've also tried various devices, OS versions, and using the Login Browser method instead. 

 

Here is my authentication code:

 

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Objects.requireNonNull(getSupportActionBar()).hide();
setContentView(R.layout.activity_splash);

authenticateSpotify();

sharedPreferences = this.getSharedPreferences("SPOTIFY", 0);
queue = Volley.newRequestQueue(this);
}

private void authenticateSpotify() {
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI);
builder.setScopes(new String[]{SCOPES});
AuthenticationRequest request = builder.build();
AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);
}

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

if (requestCode == REQUEST_CODE) {
AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);

switch (response.getType()) {
case TOKEN:
editor = getSharedPreferences("SPOTIFY", 0).edit();
editor.putString("token", response.getAccessToken());
editor.apply();
waitForUserInfo();
break;

case ERROR:
default:
break;
}
}
}

private void waitForUserInfo() {
UserService userService = new UserService(queue, sharedPreferences);
userService.getUserInfo(() -> {
User user = userService.getUser();
editor = getSharedPreferences("SPOTIFY", 0).edit();
editor.putString("userid", user.id);
editor.putString("email", user.email);
editor.putString("name", user.display_name);
editor.commit();
startMainActivity();
});
}

private void startMainActivity() {
Intent newIntent = new Intent(AuthenticateSpotify.this, MainActivity.class);
startActivity(newIntent);
}
Reply
0 Replies

Suggested posts