Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Google Silent Sign In

Hi

I'm trying to implement Google Sign In in a app that I'm testing out. I can make everything connect to Google and work without any problems however I want the app to attempt to silently log in (cached credentials) and move on if it finds them.

The only examples I can find to do this are in Java and while it's not radically different from C# I'm not really an expert in that either :)

I have taken the example from here:

https://github.com/googlesamples/google-services/blob/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin/SignInActivity.java

However I have hit what I think is a catch 22 that I would like some help with. If I use the code:

        OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.SilentSignIn(plusClient);
        if(opr != null)
        {
            if (opr.IsDone)
            {
                Console.Out.Write("we have cached login");
                try
                {
                    GoogleSignInResult signInResult = opr.Get;
                    GoogleSignInAccount gsa = signInResult.SignInAccount;

                    Toast.MakeText(this, gsa.DisplayName, ToastLength.Short).Show();

                }
                catch (Exception e)
                {
                    Console.Out.Write("error getting cache login: {0}", e.ToString());
                }
            }
            else
            {
                Console.Out.Write("we're gonna have to log in");
            }

Then the first line fails on the OptionalPendingResult section for:

CS0308 The non-generic type 'OptionalPendingResult' cannot be used with type arguments

I can drop the and the error goes away. I can then use opr.isDone so I know this is working correctly. However I then get an error on the line:

                    GoogleSignInResult signInResult = opr.Get;

CS0428 Cannot convert method group 'Get' to non-delegate type 'GoogleSignInResult'. Did you intend to invoke the method?

or, if I put brackets at the end I get

                    GoogleSignInResult signInResult = opr.Get();

CS0266 Cannot implicitly convert type 'Java.Lang.Object' to 'Android.Gms.Auth.Api.SignIn.GoogleSignInResult'. An explicit conversion exists (are you missing a cast?)

Now, I'm pretty sure the original cast that I removed is at the heart of the problem however I don't know enough about this and Google just returns java results.

Anyone able to help out?

Thanks,
Justin

Answers

  • MohamedElwyMohamedElwy USMember

    Hello Justin,
    I know its an old question, most probably you already found a solution.

    However you can solve it by casting as below:
    GoogleSignInResult result = (GoogleSignInResult)opr.Get();

    Anyway, if you posted an issue, then you found a solution, i believe it would be nice if you post the solution even if no one responded to your thread to help others how encounter same problem, or even it can help you as a reference or documentation in case you forgot how did you solve it.

    Thanks

Sign In or Register to comment.