【问题标题】:How to immediately get id token from google play services Unity Plugin如何立即从谷歌播放服务 Unity 插件获取 id 令牌
【发布时间】:2016-07-20 05:06:59
【问题描述】:

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

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

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

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

谢谢

【问题讨论】:

  • 我注意到同样的事情发生在我身上,使用的是我为我的 Unity 项目复制/修改的本机插件。我总是第一次得到一个 null 并且找不到解决它的方法。我认为这是因为从 Google 接收令牌需要一段时间,但我可能错了。

标签: c# android unity3d google-play-services


【解决方案1】:

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

PlayGamesPlatform.Instance.GetIdToken(Callback)

有回调函数。

【讨论】:

    【解决方案2】:

    如果您想在自己的 Web 服务上识别用户,最好使用服务器身份验证代码。将此发送到您的服务器并通过 jwt 从 google 获取用户身份。

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

    【讨论】:

      猜你喜欢
      • 2013-07-21
      • 2014-04-17
      • 1970-01-01
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      相关资源
      最近更新 更多