0

Hello im coding an app on xamarin c#, I have already created a button which will be in charge of logging in with google. Im using firebase for do this. I've upload "google-services.json" compilation on "GoogleServicesJson".

When i click on the login google button i select the gmail account and then i got an error: 10

using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using AndroidX.AppCompat.App;
using Google.Android.Material.BottomNavigation;
using Android.Content;
using AndroidX.CardView.Widget;
using System;
using Android.Webkit;
using System.Collections.Generic;
using System.Text;
using AndroidX.Core.Content.Resources;
using Android.Content.Res;
using Firebase.Auth;
using Android.Gms.Auth.Api.SignIn;

private GoogleSignInClient mGoogleSignInClient;

       protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.MainLogin);

            // Configure Google Sign In
            GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                .RequestIdToken("899941163980-8itmet9oqfhmbmfdk8ohoqad4evnivgh.apps.googleusercontent.com")
                .RequestEmail()
                .Build();

            mGoogleSignInClient = GoogleSignIn.GetClient(this, gso);

            Button loginButton = FindViewById<Button>(Resource.Id.loginButton);
            loginButton.Click += LoginButton_Click;
        }

        protected override async void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == 9001)
            {
                try
                {
                    var result = await GoogleSignIn.GetSignedInAccountFromIntentAsync(data);
                    if (result != null)
                    {
                        GoogleSignInAccount account = result;
                        var credential = GoogleAuthProvider.GetCredential(account.IdToken, null);
                        var authResult = await FirebaseAuth.Instance.SignInWithCredentialAsync(credential);

                        InitializeAfterLogin();
                        SetContentView(Resource.Layout.activity_main);
                    }
                    else
                    {
                        Toast.MakeText(this, "Error al iniciar sesión con Google.",                     ToastLength.Short).Show();
                    }
                }
                catch (Exception e)
                {
                    Toast.MakeText(this, "Error al iniciar sesión con Google.", ToastLength.Short).Show();
                    Console.WriteLine("Error: " + e.Message);
                }
            }
        }

        private void LoginButton_Click(object sender, EventArgs e)
        {
            Intent signInIntent = mGoogleSignInClient.SignInIntent;
            StartActivityForResult(signInIntent, 9001);
        }

        private void InitializeAfterLogin()
        {
            textMessage = FindViewById<TextView>(Resource.Id.message);
            BottomNavigationView navigation = FindViewById<BottomNavigationView>(Resource.Id.navigation);
            navigation.SetOnNavigationItemSelectedListener(this);

            RunOnUiThread(() => LoadSavedNotesAsync());

            Button editTextButton = FindViewById<Button>(Resource.Id.edit_text_button);
            editTextButton.Click += EditButton_Click;

            Button optionsButton = FindViewById<Button>(Resource.Id.options_button);
            optionsButton.Click += OptionsButton_Click;
        }
ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • 1
    "i got an error: 10" is not a very helpful description. Are you getting an exception or return code with that value, or is "10" displayed in the Google UI. Can you post a screenshot? – Jason May 06 '23 at 18:10
  • https://stackoverflow.com/questions/49450140/google-signin-api-exception-10 – Jason May 06 '23 at 18:19
  • You can check the [Google SignIn Fails with code 10 (on Android)](https://github.com/googlesamples/google-services/issues/360). There are a lot of solutions to solve the issue. – Guangyu Bai - MSFT May 10 '23 at 09:43

0 Answers0