【问题标题】:Spotify logout on android在 Android 上注销 Spotify
【发布时间】:2016-08-31 18:44:47
【问题描述】:

我有此代码可以登录以在我的应用中进行 spotify。我使用的是官方的 spotify 库。

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);
}

我现在想知道如何创建注销按钮。因为一旦登录,如果我再次按下登录按钮,它就会返回。所以我无法更改用户。我没有在 java 文档中找到任何东西。

【问题讨论】:

  • 你不知道怎么做onClick? google "android xml onClick" 你会找到它
  • 我不知道如何为当前登录的 spotify 用户执行注销。按下按钮不是问题

标签: java android spotify


【解决方案1】:

我刚刚找到了这个document,它看起来与您粘贴的登录代码相似。

其中提到了一些注销用户的方法,但我认为您需要的主要代码块是:

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

我会去查看我上面链接的那篇文章,因为有些极端情况可能对您的项目很重要。

编码愉快!

【讨论】:

  • 我试过了,还是不行。这似乎只在通过 webbrowser 执行登录时才有效,而不是使用 AuthenticationClient。
  • 再看一下文档,看起来可能也实现了回调方法。这将存储访问令牌。您还需要清除它。查看此解决方案以获取完整的登录和注销示例:github.com/pmwisdom/cordova-spotify-plugin/blob/master/src/…
猜你喜欢
  • 2017-10-31
  • 2017-06-23
  • 1970-01-01
  • 2017-01-25
  • 1970-01-01
  • 2014-02-16
  • 1970-01-01
  • 2022-06-19
  • 1970-01-01
相关资源
最近更新 更多