Forum Libraries, Components, and Plugins

Xamarin Facebook Android SignIn ?

I am trying to get basic login with Xamarin Facebook working with Android. Here are my packages.

  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
  <package id="Xamarin.Facebook" version="4.4.0.2" targetFramework="monoandroid60" />
  <package id="Xamarin.Facebook.Android" version="4.4.0.1" targetFramework="monoandroid60" />
  <package id="Xamarin.Forms" version="2.2.0.45" targetFramework="monoandroid60" />

I am following the tutorials here :

https://components.xamarin.com/view/facebookandroid
https://components.xamarin.com/gettingstarted/facebookandroid

My biggest blocker is that the documentation is completely out of date. For instance, much of the work revolves around a 'Session' object which no longer exists. I tried refactoring the example to the new API, but nothing seems to work (init never completes, no exception). Here is some sample code.

  [Activity(Label = "")]
    public class FBActivitity : Activity
    {
        public class FBInitCallback : FacebookSdk.IInitializeCallback
        {
            public IntPtr Handle { get; }

            public FBActivitity Activity;

            public void OnInitialized()
            {
Xamarin.Facebook.Login.LoginManager.Instance.LogInWithReadPermissions(Activity,
                    new string[] {"public_profile", "email"});
            }

            public void Dispose()
            {
            }
        }

        protected async override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Xamarin.Facebook.FacebookSdk.SdkInitialize(this, new FBInitCallback {Activity = this});
        }
    }

I have tried rolling back to older version of the Facebook SDK but ran into errors due to circular resource dependencies.

Lastly, we did get something working using Xamarin.Auth and a WebView. We are unhappy with this working solution as it requires a user to sign in with a username and password without any help from cookies or autocomplete. For Facebook sign in to have value, we would need the native 'one click' sign on.

Tagged:
Sign In or Register to comment.