Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7190

App crash when I call sign in or sign out with Google (Unity)

$
0
0

When I run the program and click sign in or sign out, the program immediately crashes. I use latest packages like: google sign in plugin, Firebase Auth, Base, Storage ... I downloaded google-services.json, added the keys to the console, turned on authentication, wrote the code, checked and here this error appeared. I can attach more files to help solve the problem. Thanks.

It's my sign in script:

using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Firebase;using Firebase.Auth;using Google;using UnityEngine;using UnityEngine.UI;public class GoogleSignInDemo : MonoBehaviour{    public Text infoText;    public string webClientId = "Client Id";    private FirebaseAuth auth;    private GoogleSignInConfiguration configuration;    private void Awake()    {        // RequestEmail is true if you want to get the email adress, else false.        configuration = new GoogleSignInConfiguration { WebClientId = webClientId, RequestEmail = true, RequestIdToken = true };        CheckFirebaseDependencies();    }    private void CheckFirebaseDependencies()    {        FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task =>        {            if (task.IsCompleted)            {                if (task.Result == DependencyStatus.Available)                    auth = FirebaseAuth.DefaultInstance;                else                    AddToInformation("Could not resolve all Firebase dependencies: " + task.Result.ToString());            }            else            {                AddToInformation("Dependency check was not completed. Error : " + task.Exception.Message);            }        });    }    // these 2 functions are called when clicking the button from unity.    public void SignInWithGoogle() { OnSignIn(); }    public void SignOutFromGoogle() { OnSignOut(); }    private void OnSignIn()    {        GoogleSignIn.Configuration = configuration;        GoogleSignIn.Configuration.UseGameSignIn = false;        GoogleSignIn.Configuration.RequestIdToken = true;        AddToInformation("Calling SignIn");        GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);    }    private void OnSignOut()    {        AddToInformation("Calling SignOut");        GoogleSignIn.DefaultInstance.SignOut();    }    public void OnDisconnect()    {        AddToInformation("Calling Disconnect");        GoogleSignIn.DefaultInstance.Disconnect();    }    internal void OnAuthenticationFinished(Task<GoogleSignInUser> task)    {        // if it failed, then show the error. Else continue with firebase.        if (task.IsFaulted)        {            using (IEnumerator<Exception> enumerator = task.Exception.InnerExceptions.GetEnumerator())            {                if (enumerator.MoveNext())                {                    GoogleSignIn.SignInException error = (GoogleSignIn.SignInException)enumerator.Current;                    AddToInformation("Got Error: " + error.Status +" " + error.Message);                }                else                {                    AddToInformation("Got Unexpected Exception?!?" + task.Exception);                }            }        }        else if (task.IsCanceled)        {            AddToInformation("Canceled");        }        else        {            AddToInformation("Welcome: " + task.Result.DisplayName +"!");            AddToInformation("Email = " + task.Result.Email);            AddToInformation("Google ID Token = " + task.Result.IdToken);            AddToInformation("Email = " + task.Result.Email);            SignInWithGoogleOnFirebase(task.Result.IdToken);        }    }    private void SignInWithGoogleOnFirebase(string idToken)    {        Credential credential = GoogleAuthProvider.GetCredential(idToken, null);        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>        {            AggregateException ex = task.Exception;            // check for error.            if (ex != null)            {                if (ex.InnerExceptions[0] is FirebaseException inner && (inner.ErrorCode != 0))                    AddToInformation("\nError code = " + inner.ErrorCode +" Message = " + inner.Message);            }            else            {                AddToInformation("Sign In Successful.");            }        });    }    // these 2 functions are currently not used in this demo. but you can use it as per your need.    public void OnSignInSilently()    {        GoogleSignIn.Configuration = configuration;        GoogleSignIn.Configuration.UseGameSignIn = false;        GoogleSignIn.Configuration.RequestIdToken = true;        AddToInformation("Calling SignIn Silently");        GoogleSignIn.DefaultInstance.SignInSilently().ContinueWith(OnAuthenticationFinished);    }    public void OnGamesSignIn()    {        GoogleSignIn.Configuration = configuration;        GoogleSignIn.Configuration.UseGameSignIn = true;        GoogleSignIn.Configuration.RequestIdToken = false;        AddToInformation("Calling Games SignIn");        GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);    }    private void AddToInformation(string str) { infoText.text += "\n" + str; }}

Viewing all articles
Browse latest Browse all 7190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>