48 thoughts on “Google native login with Xamarin.Forms

  1. First of all I’d like to say thank you for the sample Daniel, Great Work! I ran the sample app and when I select an account, I always get an alert message that states “an error occured!”

    Liked by 1 person

    1. Hey Sir, thank you! Checkout the type of the error, usually if you got this is because you left something misconfigured, if you are running the Android project, place a break point here(You should be able to see what is the error type and code that google is throwing at you) https://github.com/DanielCauser/SocialLoginSamples/blob/master/GoogleNativeLogin/GoogleNativeLogin/GoogleNativeLogin.Droid/GoogleManager.cs#L59

      If you are debugging the iOS project, place a break point here(Also it is the delegate that gets called by google manager after the login completes)
      https://github.com/DanielCauser/SocialLoginSamples/blob/master/GoogleNativeLogin/GoogleNativeLogin/GoogleNativeLogin.iOS/GoogleManager.cs#L41

      Like

      1. me too, i debug the code, on the protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) the resultCode is Canceled,

        Liked by 1 person

      2. Anggi, make sure you are selecting your google account, Canceled status means you probably miss clicked the google account popup =P

        Like

      3. hi daniel, i make sure that i click my google profile, i even deploy to my real phone, and it still the same error,
        please help me on this,,

        Liked by 1 person

    1. Make sure you have the instance of the google manager being resolved to the static property of the GoogleManager service, you can see it right here: https://github.com/DanielCauser/SocialLoginSamples/blob/master/GoogleNativeLogin/GoogleNativeLogin/GoogleNativeLogin.Droid/GoogleManager.cs#L31

      Also, make sure you are handling the dependency injection on the MainActivity.cs like this example https://github.com/DanielCauser/SocialLoginSamples/blob/master/GoogleNativeLogin/GoogleNativeLogin/GoogleNativeLogin.Droid/MainActivity.cs#L34

      Like

  2. I noticed that when the user has a profile picture, The sign in process is successful, but when you sign in a user without a profile pic, then all the exceptions start, because unlike the iOS project there is no way to check if the PhotoUrl is available or not. I have a solution though. Once again, Thank you Daniel, I really appreciate your assistance.

    Liked by 1 person

  3. Sorry for the late reply Anggi, but if you look in the GoogleManager.cs where the profile photo is set ‘Picture = new Uri(accountt.PhotoUrl.ToString())’, thats where the problem is, here’s a link with a pull requested to the repo that contains the changes I made to the code. Hope this helps 🙂

    Liked by 1 person

  4. Oh and another thing you might want to consider Anggi,don’t change anything when you’re running the sample project provided by Daniel(emphasis on the google-services.json file). The only time you need to change that file is when you’re planning on moving the code into your own project

    Liked by 1 person

    1. That is correct because I have not taken down the APP on my google developer portal hehe. I might just leave it there anyway =P but I encourage people to use this code and follow the configuration steps of the post!

      Like

  5. Obs: If you replace the google-services.json file on the sample project and change the Xamarin.Android package name to yours, the android.

    I do not understand what you mean by this: and change the Xamarin.Android package name to yours

    You can support me

    Liked by 1 person

    1. So, basically what I mean is you are supposed to change the file on the project, by the one you are going to generate for yourself in the google developer portal! After this, you will need to go to the android project properties and change the package name that I have added there, by the one you created on your google developer portal, you can see it in the Step 2 of the section Xamarin Android Project Setup os the post!

      Like

      1. The fact the following:

        1. Download from the github repository
        2. download the json file and replace the one contained in the project
        3. change the package name or also called (package)

        what happens is that the application starts approximately one second and then it does not work

        Like

  6. thank you very much you can compile .. just a query. It is possible to login in another part of my project that is not App.cs, that is, in x.cs page of my project. I’m looking to login after a preview of my application

    Like

    1. Yeah man, you can use this login page wherever you want in your APP, the sample project is a way I figured out of getting the most out of code sharing, you can see that all the calls begin and end on our shared code project, and the target platform projects handle the nuances of login flow.

      Like

  7. Hello,

    I am having trouble on the iOS version.
    In the Google manager class when the method PresentViewController is called the _viewController is null and the app crashes. Do you know what this could be?

    Thank you in advance

    Like

    1. Hey Alex, thank you for your thoughts on the blog, it really makes me happy to have feedback from the community! I have been blogging for 5-6 months now, but I have always used blogs as a way to get information and a resource for news and updates =D. I tried to keep the layout here as simple and clean as I could, so it is easy for people to find what they ended up here for!

      THank you for your feedback! Cheers!

      Like

  8. Fantastic site. Plenty of useful info here. I am sending it to several pals ans additionally sharing in delicious. And certainly, thanks for your effort!

    Like

  9. when I created the sample app as apk and installed it doesn’t work shows the alert with Error occured.but one thing is in debug and release mode direct run the appliication to device is working. why it makes the issues? Please figureit out

    Like

  10. For those with problems (Error 10 or simply “an error occured”). You need to put the following command EXACTLY as it is, changing only the [USERNAME]:

    “keytool -list -v -keystore “C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore” -alias androiddebugkey -storepass android -keypass android”

    The tutorial already says this, however I thought I had to change the storepass “android” to my actual password, and the alias “androiddebugkey” to my actual alias, but this is not correct.

    This command regenerates a temporary SHA-1 (instead of your actual one), and it will work only for debug. It uses this false keystore (stored in the Xamarin directory specified in the command).

    When you are about to release your project, you must change it to your correct keystore, alias and passwords, as seen here: http://www.jomendez.com/2017/08/30/ionic-2-google-sign-in-error-10-with-firebase/

    To make it easier for yourself, first find the path (“C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore”) and verify that the file debug.keystore is there. Only then, try to run the command.

    Liked by 1 person

      1. Glad to help! It is really hard to find helpful Xamarin information on the web, and your post was a godsend! This Google login was giving me nightmares, and I even had to release a project with only Facebook login, because I couldn’t make it work on time 😐
        In my case, I also had to update my Visual Studio 2017 to the latest update (I didn’t know VS versions were tied to Xamarin versions, so I couldn’t download Google Repository – and to make things worse, the error was something about MD5 not matching… Damn it…
        Seriously, we deserve a medal for every accomplishment using Xamarin, what a messy technology.
        And greetings from Brazil (eu também sou brasileiro haha)!
        Abraços!

        Like

  11. Hey Daniel, Don’t know if you’ve ever come across an issue like this, but when the google login works fine in my development environment, even when I set the app to release, now that I’ve published the app I’m getting google sign in error with a status code of 10.

    Like

    1. Hey clif! You need to setup the google login for the app version that you will send to the store. I mentioned it on the post: “For this example we will use a debug key, to publish your app the store, you will need a different SHA-1 key. You can read more about it here.” Here is the link! Even thought it talks about google maps shakey, it is the same process for using google longin in production 🙂 https://docs.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/obtaining-a-google-maps-api-key?tabs=vswin#production-keys

      Like

  12. Thanks for Native login in Facebook and Google i successfully logged in but please show me a way where i don’t need to login back when i am authenticated. Because when i close my application and again i open it then it redirects me to login page again. Please help 🙂 Beginners Question

    Like

  13. Hi Daniel.
    That is really a very helpful article
    I have the same issue here that Clifton has
    I generated the hash key on my local and test it and it worked like a charm
    but my problem now is I have to upload the apk to the store, I tried to follow the link it was very confusing
    is there any steps that we should follow or a better link

    Thanks in advance

    Like

    1. I think I found the solution, I just generate the SH1 code from the generated store key and download the new json file and everything is great now,
      obs. if the app crash after this update you should go to Properties -> Android Options -> Advanced and select armeabi + x86
      Thanks again Daniel

      Like

  14. Hi Daniel. I hope you’re doing well. I have a problem with this `using GoogleNativeLogin.Models;` It’s not taking GoogleNativeLogin for some reason. I have GooglePlayServices.Auth added to the References form NuGet. Any idea what’s causing this? Not a lot’s there on Google about it either.

    Thanks in advance for the help!

    Like

  15. Hi Daniel.
    I am having a problem with google login on IOS.
    I am getting: “Native linking error: 1 duplicate symbol for architecture x86_64” when I add the google manager class and when i am adding :
    “var googleServiceDictionary = NSDictionary.FromFile(“GoogleService-Info.plist”);
    SignIn.SharedInstance.ClientID = googleServiceDictionary[“CLIENT_ID”].ToString();”

    Do you have any idea about this error?

    Like

  16. Hey Daniel, I found a missing part in your article. GoogleService-Info.plist must set BundleResource as BuildAction. (Right click to GoogleService-Info.plist file -> Properties -> BuildAction -> BundleResource). Otherwise googleServiceDictionary will always null.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s