Spotify logout on android

时间:2016-08-31 18:44:47

标签: java android spotify

i have this code to log in to spotify in my app. I using the offical spotify lib.

public void spotifyLoginBtnClicked(View v){

    //start the authentication for spotify
    AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(clientID, AuthenticationResponse.Type.TOKEN, redirectURI);
    builder.setScopes(new String[]{"user-read-private", "streaming"});
    AuthenticationRequest request = builder.build();

    // open LoginActivity
    AuthenticationClient.openLoginActivity(this, activityIdentification, request);
}

Im wondering now how i can create a logout button. Because once logged in, if i press the login button again, it just returns. So i'am unable to change the user. I havent found anything in the java doc.

1 个答案:

答案 0 :(得分:0)

I just found this document which looks similar to the code you pasted for logging in.

In there it mentions a few methods for logging the user out but I think the main block of code you will need is:

To log out and clear all stored tokens, use the AuthenticationClient#clearCookies method. Both Spotify and Facebook tokens will be removed.

I would go and check that article I linked above as there is edge cases that might be important for your project.

Happy Coding!