1

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.

Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
cyden
  • 11
  • 1
  • you don't know how to do onClick? google "android xml onClick" and you will find it – Zoe Aug 31 '16 at 18:47
  • i dont know how to perform a logout for the currently logged in spotify user. The button press is not the problem – cyden Aug 31 '16 at 18:50

1 Answers1

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!

JodiMiddleton
  • 310
  • 1
  • 8
  • I tried it, but it doesn't work. This only seems to work if the login was performed via webbrowser, not with the AuthenticationClient. – cyden Aug 31 '16 at 18:56
  • Looking at the documentation a little more it looks like might have implemented a call back method as well. That will be storing the access token. You will also need to clear that. Have a look at this solution for a full login and logout example: https://github.com/pmwisdom/cordova-spotify-plugin/blob/master/src/android/CDVSpotify.java – JodiMiddleton Aug 31 '16 at 19:16