过去几天我面临一个问题:在我的 android 设备中安装了 spotify 应用程序后,在我的应用程序中登录 spotify。
在我的设备中安装 spotify 应用程序之前,它可以正常工作登录和注销,但是在安装 spotify 应用程序时不能..
我在我的 android studio 中使用这些。
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta12@aar'
compile 'com.spotify.sdk:spotify-player:1.0.0-beta12@aar'
使用以下代码登录:
AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI);
builder.setScopes(new String[]{"user-read-private", "user-read-birthdate", "user-read-email", "streaming"});
AuthenticationRequest request = builder.build();
AuthenticationClient.openLoginActivity(activity, REQUEST_CODE, request);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
final AuthenticationResponse authResponse = AuthenticationClient.getResponse(resultCode, data);
switch (authResponse.getType()) {
// Response was successful and contains auth token
case TOKEN:
Log.d("AccessToken", "" + authResponse.getAccessToken());
Toast.makeText(activity, "Login successfully", Toast.LENGTH_SHORT).show();
onBackPressed();
break;
// Auth flow returned an error
case ERROR:
// Handle error response
Toast.makeText(activity, "ERROR..", Toast.LENGTH_SHORT).show();
break;
case EMPTY:
Toast.makeText(activity, "EMPTY..", Toast.LENGTH_SHORT).show();
break;
// Most likely auth flow was cancelled
default:
// Handle other cases
}
}