【问题标题】:Spotify's Android SDK returns a Type.EMPTY Authentication Response only when the Spotify App is installedSpotify 的 Android SDK 仅在安装 Spotify 应用程序时返回 Type.EMPTY 身份验证响应
【发布时间】:2019-11-22 07:25:33
【问题描述】:

下面是我正在运行的代码:

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

    Log.e("Spotify Auth", "Running login activity pt 2. result code: " + resultCode + " Request Code: " + requestCode);

    if(requestCode == 200){
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, resultIntent);

        //log and store for later use
        if(response.getType() == AuthenticationResponse.Type.TOKEN) {
            Log.e("Access Token Received", response.getAccessToken());

            getSharedPreferences("appPrefs", getApplicationContext().MODE_PRIVATE)
                    .edit().putString("spotify_token", response.getAccessToken()).apply();

        } else if(response.getType() == AuthenticationResponse.Type.ERROR)
            Log.e("Spotify Access Token", "Code: " + response.getCode() + " Token failure: " + response.getError());
        else
            Log.e("Spotify Access Token", response.getType().name() + " " + response.getError() + " Token: " + response.getAccessToken());

    } else {
        Log.e("Spotify Access Token", "Token failure: " + resultCode + "   " + requestCode);
    }
}

public void getSpotifyAuth() {
    //spotify token setup
    AuthenticationRequest.Builder builder =
            new AuthenticationRequest.Builder(
                    getString(R.string.spotify_keys).split(":")[0],
                    AuthenticationResponse.Type.TOKEN,
                    "com.lattestudios.musicpal://auth");
    builder.setShowDialog(true);
    AuthenticationRequest request = builder.build();
    AuthenticationClient.openLoginActivity(this, 200, request);
}

未安装 spotify 应用程序时一切正常。它会弹出一个要求登录的窗口,然后用户单击同意,SDK 返回一个令牌。但是,当安装了 spotify 应用程序时,会弹出一个非常快速的加载屏幕而不是登录屏幕,因为它正在尝试从应用程序获取令牌。当这种情况消失时,onActivityResult 函数中给出的响应是 EMPTY 类型。请求码正确,结果码为-1,错误信息和访问令牌为空。

如果您想查看我的其余代码,可以找到 here on my GitHub。谢谢!

【问题讨论】:

  • 在你的情况下预期的输出是什么?
  • @LucasWieloch 我期待收到一个身份验证令牌。基于the documentation,它似乎应该只从应用程序获取一个令牌并正常返回它,而不是像没有安装Spotify那样显示弹出窗口,而是返回Type.TOKEN而不是Type.EMPTY。
  • 我们还在设备上安装了 Spotify 应用程序的 api 19 上遇到了这个空响应。如果我卸载了 Spotify 应用程序并通过浏览器获得授权工作正常。它仅发生在 api 19 上。 19以上工作正常。请帮助确定问题。
  • @SakthivelAppavu 检查我在下面发布的答案,这是字符串的问题

标签: java android authentication spotify spotify-app


【解决方案1】:

我有同样的问题,我根据这个 GitHub 文档 https://github.com/spotify/android-auth 弄乱了字符串

<resources>
    <string name="com_spotify_sdk_redirect_scheme">yourscheme</string>
    <string name="com_spotify_sdk_redirect_host">yourhost</string>
</resources>

确保正确放置方案和主机 例如,如果重定向 url 是播放列表/回调,则将 com_spotify_sdk_redirect_scheme 设置为播放列表,将 com_spotify_sdk_redirect_host 设置为回调 或者您也可以使用这两个字符串创建重定向主机

private fun getRedirectUri(): Uri {
    return Uri.Builder()
        .scheme(getString(R.string.com_spotify_sdk_redirect_scheme))
        .authority(getString(R.string.com_spotify_sdk_redirect_host))
        .build()
}

还要确保 Spotify 仪表板上的重定向 URI 与这两个和清单中的一个匹配。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,发现它是由于尝试在所有 *.spotify.com 域中使用带有 Charles Proxy 的 SSL 代理引起的。在我将其更改为api.spotify.com 后,登录开始工作。

    【讨论】:

      猜你喜欢
      • 2020-07-05
      • 2019-01-08
      • 1970-01-01
      • 2018-06-19
      • 2022-08-04
      • 2016-07-15
      • 2020-06-18
      • 2017-06-23
      • 2017-10-30
      相关资源
      最近更新 更多