因此,我尝试通过将其与Firebase混合使用来在Unity Apps上制作Google登录选项。因此,我导入了Google登录插件v1.04并编写了代码。将其构建为* .apk文件时,控制台上不会显示任何错误。但是,当我尝试登录时,在选择了我要用来登录的帐户后,它会强制关闭。这是我的完整代码:
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google;
using UnityEngine;
using Firebase.Auth;
public class googleAuth : MonoBehaviour
{
[SerializeField] string webClientID = "190747548795-haa9ej8fkg584c1r5nkhu7u6ol50tmcf.apps.googleusercontent.com";
GoogleSignInConfiguration configuration;
private void Awake() {
configuration = new GoogleSignInConfiguration{
WebClientId = webClientID,
RequestIdToken = true
};
}
public void loginGoogle(){
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
}
void OnAuthenticationFinished(Task<GoogleSignInUser> task){
if(task.IsCanceled)
print("error");
if(task.IsFaulted)
print("error");
if(task.IsCompleted){
googleFirebase(task.Result.IdToken);
}
}
void googleFirebase(string token){
Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(token,null);
FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential);
}
}
这意味着您缺少Plugins / Android /文件夹中的文件。
您可以查看我有关Unity3D https://medium.com/@capcomin/unity3d-google-signin-for-android-ios-games-fd59e4b6f027登录Google的文章>