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进行测试。但是在真实设备上运行应用程序后,我得到了一个有趣的结果。我知道了:
配置已创建 配置初始化 启用 尝试登录
我认为如果从公共void SignInWithPlayGames()方法中(成功)跳过它。我的应用程序从不显示Google Play用户界面,现在不确定我是否使用正确的代码。
答案 0 :(得分:2)
在过去的几周里,我在Google Play上经历了很多挣扎。但是,我没有在构建器中检索ID令牌或auth令牌。这可能会给您带来麻烦。
此外,您需要将社交用户转换为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
}
}