编辑:能够修复问题是关键。我已经将我的应用程序上传到谷歌控制台,并在应用程序完整性下使用他们的Sha1密钥。
我是Unity和Firebase/GoogleSignin的新手。
- 试图在Unity中通过Firebase设置谷歌登录按钮。
- 使用Unity 2021.3.6f1,构建用于Android 6+,脚本后端:IL 2CPP,api每个平台的兼容性级别:.Net标准2.1,目标体系结构:ARMv7和ARM 64,非开发版本,Firebase项目设置Prod-Tag不是生产版本
我的脚步
- 使用playersettings中的包名创建了Unity firebase项目
- 下载google-services.json并添加到资产文件夹
- 下载(Firebase Unity SDK 9.3.0)FirebaseAuth.unitypackage和谷歌登录插件-1.0.4.unitypackage并将两者导入到Unity中(跳过谷歌登录插件的解析,从解析FirebaseAuth中删除net 3.5 unity.tasks.dll和unity.compat.dll)
- 启用身份验证-〉登录方法-〉google(来自google-services.json的Web客户端ID匹配)
- 使用Unity上的密钥库管理器生成密钥库(puplishing设置),使用java keytool读取SHA-256指纹并添加到firebase项目设置中。
- 已使用google-services.json中的WebClient ID OAuth客户端ID类型3
- 构建应用程序并安装在手机上,并抛出以下错误:
DeveloperError Exception of type 'Google.GoogleSignIn+SignInException' was thrown.
我的密码:
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Firebase;
using Firebase.Auth;
using Firebase.Extensions;
using Google;
using System.Net.Http;
public class FirebaseGoogleLogin : MonoBehaviour
{
public Text warning;
public Animator anWarning;
private bool fireBaseReady;
private GoogleSignInConfiguration configuration;
Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
Firebase.Auth.FirebaseAuth auth;
Firebase.Auth.FirebaseUser user;
void Awake()
{
configuration = new GoogleSignInConfiguration
{
WebClientId = "XXX from google-services.json",
RequestIdToken = true
};
}
private void Start()
{
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
}
public void OnSignIn()
{
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
GoogleSignIn.Configuration.RequestEmail = true;
user = auth.CurrentUser;
if (user != null)
{
warning.text = "User signed in successfully:" + user.Email + " " + user.UserId;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
else
{
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
}
}
internal void OnAuthenticationFinished(Task<GoogleSignInUser> task)
{
//TaskCompletionSource<FirebaseUser> signInCompleted = new TaskCompletionSource<FirebaseUser>();
//signIn.ContinueWith(task => {
if (task.IsCanceled)
{
warning.text = "1:" + task.Exception;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
else if (task.IsFaulted) //ERROR OCCURS HERE
{
using (IEnumerator<System.Exception> enumerator =
task.Exception.InnerExceptions.GetEnumerator())
{
if (enumerator.MoveNext())
{
GoogleSignIn.SignInException error =
(GoogleSignIn.SignInException)enumerator.Current;
warning.text = "Got Error: " + error.Status + " " + error.Message;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
else
{
warning.text = "Got Unexpected Exception?!?" + task.Exception;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
}
}
else
{
warning.text = "3";
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(((Task<GoogleSignInUser>)task).Result.IdToken, null);
auth.SignInWithCredentialAsync(credential).ContinueWith(authTask => {
if (authTask.IsCanceled)
{
warning.text = "auth task canceled:" + authTask.Exception;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
else if (authTask.IsFaulted)
{
warning.text = "auth task is faulted:" + authTask.Exception;
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
else
{
warning.text = "User signed in successfully:";
anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
}
});
}
// });
}
}
OnSignIn通过按下按钮启动。
错误发生在“internal void OnAuthenticationFinished(Task<GoogleSignInUser> task)
”-〉“(task.IsFaulted)
”处
我在FirebaseGoogleLogin.cs脚本旁边的Unity中没有控制台错误/构建错误:
Error CS0433: The type 'Task' exists in both 'Unity.Tasks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=XXX' Assembly-CSharp, Assembly-CSharp.Player
但是人们说这很普遍,应该不会有什么问题。
请经过吨小时的工作,这一点,谁能告诉我,我犯了什么错误?
1条答案
按热度按时间k7fdbhmy1#
我建议您使用try/catch块捕获异常,并调试错误消息以了解更多细节。