firebase - 谷歌玩游戏身份验证与 Firebase 无法在 Unity 上运行
问题描述
我已按照官方说明https://firebase.google.com/docs/auth/unity/play-games在 Unity 上使用 firebase 配置 google play 游戏身份验证,但不幸的是它不起作用。我认为当它试图从玩游戏中请求身份验证 ID 时,身份验证过程失败了。这里是来自 logcat 的日志:
12-08 16:27:12.665 2665 2695 I Unity : GPGClient:Start()
12-08 16:27:12.665 2665 2695 I Unity :
12-08 16:27:12.665 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:12.665 2665 2695 I Unity :
12-08 16:27:18.980 2665 2695 I Unity : authcode
12-08 16:27:18.980 2665 2695 I Unity : GPGClient:SignIn()
12-08 16:27:18.980 2665 2695 I Unity :
12-08 16:27:18.980 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:18.980 2665 2695 I Unity :
12-08 16:27:18.990 2665 2695 I Unity : punto0
12-08 16:27:18.990 2665 2695 I Unity : GPGClient:SignIn()
12-08 16:27:18.990 2665 2695 I Unity :
12-08 16:27:19.003 2665 2695 I Unity : Starting Auth with token client.
12-08 16:27:19.003 2665 2695 I Unity : GooglePlayGames.Android.AndroidClient:Authenticate(Action`2, Boolean)
12-08 16:27:19.003 2665 2695 I Unity : GPGClient:SignIn()
12-08 16:27:19.003 2665 2695 I Unity :
12-08 16:27:19.010 2665 2695 I Unity : punto1
12-08 16:27:19.343 2665 2695 W Unity : !!! [Play Games Plugin DLL] 12/08/19 16:27:19 +01:00 WARNING: Creating new PlayGamesPlatform
12-08 16:27:19.343 2665 2695 W Unity : System.Action:Invoke()
12-08 16:27:19.343 2665 2695 W Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:19.343 2665 2695 W Unity :
12-08 16:27:19.343 2665 2695 W Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:19.343 2665 2695 W Unity :
12-08 16:27:19.345 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:19 +01:00 DEBUG: Activating PlayGamesPlatform.
12-08 16:27:19.345 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:19.345 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:19.345 2665 2695 I Unity :
12-08 16:27:19.345 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:19.345 2665 2695 I Unity :
12-08 16:27:19.347 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:19 +01:00 DEBUG: PlayGamesPlatform activated: GooglePlayGames.PlayGamesPlatform
12-08 16:27:19.347 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:19.347 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:19.347 2665 2695 I Unity :
12-08 16:27:19.347 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:19.347 2665 2695 I Unity :
12-08 16:27:19.349 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:19 +01:00 DEBUG: Creating platform-specific Play Games client.
12-08 16:27:19.349 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:19.349 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:19.349 2665 2695 I Unity :
12-08 16:27:19.349 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:19.349 2665 2695 I Unity :
12-08 16:27:19.351 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:19 +01:00 DEBUG: Creating Android IPlayGamesClient Client
12-08 16:27:19.351 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:19.351 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:19.351 2665 2695 I Unity :
12-08 16:27:19.351 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:19.351 2665 2695 I Unity :
12-08 16:27:35.648 2665 2695 I Unity : authentication message Authentication canceled
12-08 16:27:35.648 2665 2695 I Unity : GPGClient:<SignIn>b__4_0(Boolean, String)
12-08 16:27:35.648 2665 2695 I Unity : System.Action`2:Invoke(T1, T2)
12-08 16:27:35.648 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:35.648 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:35.648 2665 2695 I Unity :
12-08 16:27:35.648 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:35.648 2665 2695 I Unity :
12-08 16:27:35.652 2665 2695 I Unity : not yet autenticated
12-08 16:27:35.652 2665 2695 I Unity : System.Action`2:Invoke(T1, T2)
12-08 16:27:35.652 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:35.652 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:35.652 2665 2695 I Unity :
12-08 16:27:35.652 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:35.652 2665 2695 I Unity :
12-08 16:27:35.654 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:35 +01:00 DEBUG: Authentication canceled
12-08 16:27:35.654 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:35.654 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:35.654 2665 2695 I Unity :
12-08 16:27:35.654 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:35.654 2665 2695 I Unity :
12-08 16:27:35.672 2665 2695 I Unity : [Play Games Plugin DLL] 12/08/19 16:27:35 +01:00 DEBUG: Invoking user callback on game thread
12-08 16:27:35.672 2665 2695 I Unity : System.Action:Invoke()
12-08 16:27:35.672 2665 2695 I Unity : GooglePlayGames.OurUtils.PlayGamesHelperObject:Update()
12-08 16:27:35.672 2665 2695 I Unity :
12-08 16:27:35.672 2665 2695 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
12-08 16:27:35.672 2665 2695 I Unity :
这里的代码:
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using Firebase.Auth;
public class GPGClient : MonoBehaviour
{
private string authCode;
private FirebaseAuth auth;
public Text UserID;
private void Start()
{
Debug.Log("start");
UserID.text = "user";
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestServerAuthCode(false /* Don't force refresh */)
// requests an ID token be generated. This OAuth token can be used to
// identify the player to other services such as Firebase.
.RequestIdToken()
.Build();
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
}
public void SignIn()
{
authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
Debug.Log("authcode " + authCode);
Debug.Log("punt
{
authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
Debug.Log("authcode " + authCode);
Debug.Log("punto0");
// Google Play Games authentication.
Social.localUser.Authenticate((success, message) =>
{
Debug.Log("authentication message " + message);
if (success)
{
//authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
Debug.Log("autenticated");
GoOnSignIn();
}
else
Debug.Log("not yet autenticated");
});
Debug.Log("punto1");
}
private void GoOnSignIn()
{
Debug.Log("punto1.1");
// Firebase authentication.
auth = FirebaseAuth.DefaultInstance;
Credential credential =
PlayGamesAuthProvider.GetCredential(authCode);
Debug.Log("punto1.2");
auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
{
Debug.Log("punto2");
if (task.IsCanceled)
{
Debug.Log("punto2cancel");
UserID.text = "SignInWithCredentialAsync was canceled.";
return;
}
if (task.IsFaulted)
{
Debug.Log("punto2fault");
UserID.text = "SignInWithCredentialAsync encountered an error: " + task.Exception;
return;
}
Debug.Log("punto3");
FirebaseUser newUser = task.Result;
UserID.text = "User signed in successfully: {0} ({1})" +
newUser.DisplayName + newUser.UserId;
});
CreateUser();
}
希望有人能帮助我!谢谢!
解决方案
推荐阅读
- angular - 在Angular8中检测几个ajax请求状态的最佳专业方法是什么?
- xslt-2.0 - 如何在 XSLT 中为时间戳添加一个小时?
- java - RocksDB 时在算子(KeyedProcessFunction 和 RichMapFunction)之间共享状态
- java - 更改默认 Spring Integration DirectChannel 日志记录
- kubernetes - Zookeeper 在多次重启节点后抛出超时
- node.js - 如何使用 lambda 和 node 将生成的 PDF 上传到 s3?
- javascript - 用户在输入字段中输入数据并按下回车后触发事件
- reactjs - 在移动设备上使用 Formik 的 React-select 验证工作不正确
- javascript - 如何获取 MySQL 列的位置?
- kubernetes - 使用 Kustomize 为微服务管理 k8s 机密