Google SignIn returns Current user as null

2019-08-17 05:47发布

问题:

I am using google login for my Xamarin iOS app, however after successfully entering the username and password in the safari browser prompt that appears, It returns properties CurrentUser as null.

My Code:

Google.SignIn.SignIn.SharedInstance.Delegate = this; 
Google.SignIn.SignIn.SharedInstance.UIDelegate = this; 
Google.SignIn.SignIn.SharedInstance.SignInUser(); 
Google.SignIn.SignIn.SharedInstance.SignedIn += SharedInstance_SignedIn;

private void SharedInstance_SignedIn(object sender, SignInDelegateEventArgs e) 
{ 
var signin = (Google.SignIn.SignIn)sender; 
   //Here if i debug signin variable, its property CurrentUser comes as null
}

I am using Xamarin.IOS.Google.Signin: v4.0.1.1

Am I missing some setting that needs to be enabled in the Google api console?

回答1:

Sender indicate the class that raised the event.

To get User ,you can use e.User Or Google.SignIn.SignIn.SharedInstance.CurrentUser

here explatins the function of method SignIn

The Sign-In SDK automatically acquires access tokens, but the access tokens will be refreshed only when you call SignIn or SignInSilently methods.