2
private string text;    

 void Start()
    {

        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestIdToken().RequestServerAuthCode(false).Build();
        text = "config created";
        PlayGamesPlatform.InitializeInstance(config);
        text = text + "\n" + "config initialized";
        PlayGamesPlatform.Activate();
        text = text + "\n" + "activated";
        SignInWithPlayGames();
        text = text + "\n" + "attempted to sign in";
    }

 public void SignInWithPlayGames()
    {

        UnityEngine.Social.localUser.Authenticate((bool success) =>
        {

            if (success)
            {
                string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
                text = text + "\n" + "Auth code is: " + authCode;
                if (string.IsNullOrEmpty(authCode))
                {
                    text = text + "\n" + "Signed into Play Games Services but failed to get the server auth code.";
                    return;
                }

            }


            if (!success)
            {
                text = text + "\n" + "Failed to Sign into Play Games Services.";
                return;
            }


        });
    }

当我在 Unity 上运行它时,我得到了

配置已创建配置已初始化激活无法登录 Play 游戏服务。试图登录

这很好,因为我正在使用我的 PC 来测试它。但在真实设备上运行我的应用程序后,我得到了一个有趣的结果。我懂了:

配置创建配置初始化激活尝试登录

我认为它会从 public void SignInWithPlayGames() 方法中跳过 if (success)。我的应用从不显示 Google Play UI,我现在不确定我是否使用了正确的代码。

4

1 回答 1

2

在过去的几周里,我在使用 Google Play 时遇到了很多困难。但是,我没有在构建器中检索 ID 令牌或身份验证令牌。它可能会给你带来问题。

此外,您需要将社交用户转换为 google 用户才能访问其属性。

我让它与以下代码一起工作。(如果您无法使用此代码,则问题出在您在 googleplay 插件和/或 google play 控制台中的设置中。)

    PlayGamesClientConfiguration config = new
    PlayGamesClientConfiguration.Builder()
    .Build();

    // Enable debugging output (recommended)
    PlayGamesPlatform.DebugLogEnabled = true;

    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();

    Social.localUser.Authenticate((bool success) =>
    {
        var googleUser = ((PlayGamesLocalUser)Social.localUser);

        if (googleUser.authenticated)
        {
            // access googleUser properties and store them or use them
        }
    }
于 2018-09-18T10:09:55.023 回答