我正在尝试将Google Play服务添加到我的Android应用中。当我在Unity Editor中调用Social.localUser.Authenticate时,它会向回调函数返回false。但是当我的手机运行调试版本时,没有调用回调函数。并且没有出现错误消息。
这是我的代码。
public void Init()
{
// Initialize Play Games Configuration and Activate it.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.RequestEmail()
.RequestServerAuthCode(false)
.RequestIdToken()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.LogFormat("SignInOnClick: Play Games Configuration initialized");
}
public void SignInWithPlayGames()
{
if (Social.localUser.authenticated) {
return;
}
// Sign In and Get a server auth code.
Debug.Log("Start Auth GPGS");
Social.localUser.Authenticate((bool success) =>
{
Debug.Log("The lines below never call :("); // <<<<<<<<<<<<<<<<<<<<<<<<<<<
if (!success) {
Debug.LogError("SignInOnClick: Failed to Sign into Play Games Services.");
return;
}
string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
Debug.LogFormat("SignInOnClick: Auth code is: {0}", authCode);
if (string.IsNullOrEmpty(authCode))
{
Debug.LogError("SignInOnClick: Signed into Play Games Services but failed to get the server auth code.");
return;
}
// Use Server Auth Code to make a credential
Credential credential = PlayGamesAuthProvider.GetCredential(authCode);
// ......
});
}
我看了一些视频。我不确定我的所有步骤是否正确,因为这些视频教授如何使用Google Play服务构建新的应用。但我的项目已经启动。其他一些设置(如API凭据)已由其他设置完成。
我发现有人说应该将Android的SHA-1客户端ID从“应用程序签名证书”更改为“上载证书”。 Link here.
我还发现使用Web客户端ID代替Android。 Link here.
我已经尝试过这些修复方法,但似乎对我不起作用。有人和我有同样的问题吗?或者是否有任何设置显示此问题的更多详细信息?
我有同样的问题并通过禁用缩小来解决它。
“构建”>“播放器设置”>“发布设置”>“缩小”,这里我将Release和Debug都设置为None,它已修复。
在logcat输出中,它应该显示一些错误。类似“此应用程序未正确配置为使用GameServices,因为......”