【发布时间】:2019-04-27 21:03:25
【问题描述】:
我正在尝试将 Google Play 服务添加到我的 Android 应用中。当我在 Unity 编辑器中调用 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.
我已经尝试过这些修复方法,但似乎对我不起作用。有人和我有同样的问题吗?或者是否有任何设置显示此问题的更多详细信息?
【问题讨论】:
-
也发生在我身上。似乎 logcat 没有显示任何异常的错误或警告。它只是没有被调用。
标签: android unity3d google-play-services google-play-games