如何立即从 google 播放服务 Unity 插件获取 ID 令牌

How to immediately get id token from google play services Unity Plugin

我正在使用 https://github.com/playgameservices/play-games-plugin-for-unity 插件用他的 google 帐户登录用户,然后我想获取 Id Token 并将其发送到我的服务器并为该用户注册一个帐户我自己的 database.this 是我获取 Id 令牌的代码:

PlayGamesPlatform.Instance.Authenticate(success =>
{
    if (success)
    {
        Debug.Log("Id Token :");
        Debug.LogFormat("{0}", PlayGamesPlatform.Instance.GetIdToken());
        Debug.Log("End Of Id Token");
    }
});

问题是它第一次只打印空字符串,当我第二次(或稍后)调用它时,它打印了令牌。我想立即或通过回调获取令牌以确保收到令牌。

如何确保收到令牌?这个有回调吗?

谢谢

他们在新版本中更改了插件,现在

PlayGamesPlatform.Instance.GetIdToken(Callback)

有回调函数。

如果您想在自己的网络服务上识别用户,最好使用服务器授权码。将此发送到您的服务器并通过 jwt 从 google.

获取用户身份
                GooglePlayGames.OurUtils.PlayGamesHelperObject.RunOnGameThread(() => {

                    PlayGamesPlatform.Instance.GetServerAuthCode((CommonStatusCodes status, string code) =>
                    {                            
                        Debug.Log("Status: " + status.ToString());
                        Debug.Log("Code: " + code);

                    });

                });