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 游戏服务。 尝试登录
这很好,因为我正在使用我的电脑来测试它。但在真实设备上运行我的应用程序后,我得到了一个有趣的结果。我得到了这个:
配置已创建 配置已初始化 启用 尝试登录
我认为它会跳过 public void SignInWithPlayGames() 方法中的 if(成功)。我的应用从未显示 Google Play UI,我现在不确定我是否使用了正确的代码。
最佳答案
过去几周我在使用 Google Play 时遇到了一些困难。但是,我没有在构建器中检索 ID token 或身份验证 token 。它可能会给您带来问题。
此外,您需要将社交用户转换为 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
}
}
关于unity-game-engine - 如何将 Google Sign-In 正确集成到我的 Unity Android 应用程序构建中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52383723/