【问题标题】:Social.localUser.Authenticate callback never calledSocial.localUser.Authenticate 回调从未被调用
【发布时间】:2019-04-27 21:03:25
【问题描述】:

我正在尝试将 Google Play 服务添加到我的 Android 应用中。当我在 Unity 编辑器中调用 Social.localUser.Authenticate 时,它会向回调函数返回 false。但是当我的手机运行调试版本时,回调函数没有被调用。并且没有错误消息出来。

这是我的代码。

public void Init()
{
    // Initialize Play Games Configuration and Activate it.
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    .EnableSavedGames()
    .RequestEmail()
    .RequestServerAuthCode(false)
    .RequestIdToken()
    .Build();

    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.Activate();
    Debug.LogFormat("SignInOnClick: Play Games Configuration initialized");
}

public void SignInWithPlayGames()
{
    if (Social.localUser.authenticated) {
        return;
    }
    // Sign In and Get a server auth code.
    Debug.Log("Start Auth GPGS");
    Social.localUser.Authenticate((bool success) =>
    {
        Debug.Log("The lines below never call :("); // <<<<<<<<<<<<<<<<<<<<<<<<<<<
        if (!success) {
            Debug.LogError("SignInOnClick: Failed to Sign into Play Games Services.");
            return;
        }
        string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
        Debug.LogFormat("SignInOnClick: Auth code is: {0}", authCode);
        if (string.IsNullOrEmpty(authCode))
        {
            Debug.LogError("SignInOnClick: Signed into Play Games Services but failed to get the server auth code.");
            return;
        }

        // Use Server Auth Code to make a credential
        Credential credential = PlayGamesAuthProvider.GetCredential(authCode);
        // ......
    });
}

我看过一些视频。我不确定我的所有步骤是否正确,因为这些视频教授了如何使用 Google Play 服务构建新应用。但是我的项目已经启动了。其他一些设置(如 API 凭据)已经由其他设置完成。

我发现有人说Android的SHA-1客户端ID应该从“应用签名证书”更改为“上传证书”。 Link here.

而且我还发现使用 Web 客户端 ID 而不是 Android。 Link here.

我已经尝试过这些修复方法,但似乎对我不起作用。有人和我有同样的问题吗?或者是否有任何设置显示此问题的更多详细信息?

【问题讨论】:

  • 也发生在我身上。似乎 logcat 没有显示任何异常的错误或警告。它只是没有被调用。

标签: android unity3d google-play-services google-play-games


【解决方案1】:

我遇到了同样的问题并通过禁用缩小解决了它。

“Build”>“Player Settings”>“Publishing Settings”>“Minify”,在这里我将 Release 和 Debug 都设置为 None 并且已修复。

【讨论】:

    【解决方案2】:

    在 logcat 输出中它应该显示一些错误。 类似“此应用未正确配置为使用 GameServices,因为...”

    【讨论】:

      【解决方案3】:
      1. 资产 > 外部依赖管理器 > Android 解析器 > 删除已解析的库。
      2. 资产 > 外部依赖管理器 > Android 解析器 > 强制解析

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-01
        相关资源
        最近更新 更多