28 thoughts on “Facebook native login with Xamarin.Forms

  1. Daniel , obrigado por compartilhar!
    Só tenho uma dúvida, para implementar sem Prism? Na MainViewModel, recebe-se como parâmetros um FbManager, o que é necessário passar para ela?

    Liked by 1 person

    1. Entao, essa classe FacebookManager, e injetada na ViewModel pelo container de DI que eu usei nesse projeto(Unity) que ja vem com o Prism. Voce pode injetar essa classe na tua viewmodel com o container de DI que usar no seu projeto.


  2. Hey Daniel,
    Thanks for the amazing efforts man, really helpful.
    i’m following your article to implement fb login on android and ios
    I’m getting a problem installing facebook sdk on the Android project.
    it conflicts with the Xamarin Forms library, I always get this error

    Version conflict detected for Xamarin.Android.Support.Compat. Reference the package directly from the project to resolve this issue.
    testApp.Android -> Xamarin.Forms -> Xamarin.Android.Support.v7.MediaRouter -> Xamarin.Android.Support.v7.Palette -> Xamarin.Android.Support.Compat (=
    testApp.Android -> Xamarin.Facebook.Android 4.26.0 -> Xamarin.Android.Support.CustomTabs 25.3.1 -> Xamarin.Android.Support.Compat (= 25.3.1).

    and I’ve been on this for a while now and I can’t seem to find any common compat library between the two libraries.
    any ideas?


    1. Hey! Have you tried to make the code in the repo run, using your own configurations?

      Does your project run without the Facebook SDK? I’m not realy sure how to work around this since I can’t reproduce it on my end.

      if you find a way around this, please post here or on the repo issues on git hub! So we can keep track of it and help others that may have the same problem!


    2. You must use older packages: Xamarin.Forms 2.4.xx, Xamarin.Android.Support.Compat. I had same problem with Xamarin.Forms.Maps.


  3. Hey Amr,

    I found exactly the same problem. Stumped me for ages. However, eventually I realized that Xamarin.Android.Support.CustomTabs (I’ve bound to Oreo in my project) has been pulled in as a dependency automated (I hadn’t installed it manually).

    To get round this problem, I had to go to Nuget and install Xamarin.Android.Support.CustomTabs manually (with the same version that is already installed). After doing that, when I went to Xamarin.Facebook.Android package and was able to install it.

    The weird thing is:

    Xamarin.Facebook.Android 4.26.0 – > Xamarin.Android.Support.Compat 25.3.1 as displayed in the error message issued by nuget is misleading. If you look at the dependencies list on the Xamarin.Facebook.Android package, i says Xamarin.Android.Support.Compat >=25.3.1 (i.e. greater than or equal to), not = equal to. Not sure why that’s the case, but it doesn’t install without problems.


  4. Hi Daniel

    First of all I just want to say thank you for the Google And Facebook Native Plugin tutorials. I just wanted to know 2 things which are a bit off the topic and that you might just consider.

    1. Since you have 2 native login methods and the methods with regard to the platform have slightly different implementations, but the viewmodel for the login view is more or less the same regardless of the platform, would it be possible to simplify the viewmodel and have for e.g on Login and one Logout method instead of having GoogleLogin, FacebookLogin, GoogleLogout, FacebookLogout?

    2.Is it possible to call one of the login provider methods from anywhere in an application to find out whether or not a user is logged into a platform before logging them out.

    Thank you sooo much Daniel.

    I’d understand if you feel I’m asking for too much, thank you for your time.


  5. Hi Daniel
    I’m facing a problem with the Facebook Login for iOS, After I tap the button to login with Facebook, a webview opens and provides me with two options:
    1.Login With Email Or Phone Number
    2.Continue To Facebook Application(Login with Facebook application)
    Well they’re not exactly in those words, but something to that effect.
    After I select the option to login with the Facebook Application and confirm that I want to login, it returns back to my application but the webview with the two login options is still there. The only way the ‘call back’ function is fired is by cancelling the login by tapping on ‘Done’ in the top left of the dialog.


      1. What was the mistake? I am having the exact same issue. Any help would be much appreciated.


      2. I had to change my code in the AppDelegate from this:

        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        UIApplicationOpenUrlOptions openUrlOptions = new UIApplicationOpenUrlOptions(options);
        return SignIn.SharedInstance.HandleUrl(url, openUrlOptions.SourceApplication, openUrlOptions.Annotation);

        which is Daniel’s Native Google Login Sample, if my memory serves me correctly

        to this:

        public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        return ApplicationDelegate.SharedInstance.OpenUrl(application, url, sourceApplication, annotation);

        which is in Daniel’s Facebook Native Login Sample, the above override works for both Google Login And Facebook Login.

        Sorry for replying so late Ryan, I hope this helps you.

        Liked by 1 person

  6. I have another question though I was looking at the iOS code for the facebook login, when you’re assigning a value to the variables for example first_name or last_name, there’s a try catch block for each and every variable, why is this so, why not just have one try catch block for all of them.


  7. Hi Daniel,
    thank you for this article..
    I tried to make the code in the repo run but it didn’t . when I click facebook login it stuck on loading without opening the fb app or giving an error. any Idea how to solve this?


    1. ok It seems that the app doesn’t work in debug mode.. after I run it without debug it works well but it does not ask to continue with this account it automatically get the logged in account on the FB app and if I logged out from the app it asks to choose a user.(Is this the normal behavior?)


      1. Hey Chahid! Please post this issue in the github repo, it will be easy to track and to solve, and can help other people when we find what is wrong 🙂


  8. I want to add some fixes to to keep up to date.


    1 – You should change this line with the following:

    -You need this plugin: https://github.com/jamesmontemagno/Xamarin.Plugins to get curreny activity.

    var context = CrossCurrentActivity.Current.Activity;
    LoginManager.Instance.LogInWithReadPermissions(context as Activity as Activity, new List { “public_profile”, “email” });

    2- If you are getting “SERVER_ERROR: [code] 1675030 [message]: Error performing query. [extra]: null", there is something wrong about your configurations. For my case, it was Key Hash. I used wrong openssl version, it didn't ask me any password.

    Download and install the right version of openssl from http://slproweb.com/products/Win32OpenSSL.html. (mine is Win64 OpenSSL v1.1.1 - 43mb)

    and use following command:

    keytool -exportcert -keystore "C:\Users\[USER]\AppData\Local\Xamarin\Mono for Android\debug.keystore" -alias androiddebugkey | "C:\Program Files\OpenSSL-Win64\bin\openssl" sha1 -binary | "C:\Program Files\OpenSSL-Win64\bin\openssl" base64
    Enter keystore password: android

    iOS: I will edit this entry, after I get things done.


    1. Its normal receive this message?

      The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format


  9. Hi, its a very useful code, but i have a problem, i need to unistall my facebook app to succesfuly login in my app with facebook, and i dont know why, if i have installed the facebook app, the login in my app with facebook doesnt work.

    Liked by 1 person

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 )

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