MVVMCross Implementing Facebook Login Button

JoeHonourJoeHonour GBMember
edited September 2015 in Xamarin.Android


i am trying to implement facebook login on my app and so far i can get the facebook login button to display and when clicked, it allows you to log in. However, i can't seem to set up the callback so that i can do something once it is successful. The documentation says i need to implement RegisterCallback but in c# i don't seem to be able to set up an anonymous class as they show in the documentation.

So what i've done is create an inner class that implements the neccessary interface, but it keeps saying i have to overload public IntPtr Handle method, which i think is causing me a lot of issues.

This is the code i have so far:

view layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="" xmlns:local="" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.facebook.login.widget.LoginButton android:id="@+id/login_button" style="@style/com_facebook_loginview_default_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="30dp" android:layout_marginBottom="30dp" /> </LinearLayout>

public class LoginView : MvxActivity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); FacebookSdk.SdkInitialize (Application.Context); var CallbackManagerFactory = new CallbackManagerFactory(); var callback = CallbackManagerFactory.Create (); SetContentView (Resource.Layout.LoginViewLayout); var loginButton = (LoginButton) FindViewById(Resource.Id.login_button); loginButton.SetReadPermissions("user_friends"); // Callback registration loginButton.RegisterCallback(callback, new FacebookCallBack<LoginResult>()); } }

public class FacebookCallBack<LoginResult> : IFacebookCallback{ public IntPtr Handle{ get { throw new NotImplementedException (); //where i am having the issue } } public void OnCancel () { throw new NotImplementedException (); } public void OnError (FacebookException p0) { throw new NotImplementedException (); } public void OnSuccess (Java.Lang.Object p0) { throw new NotImplementedException (); } public void Dispose () { throw new NotImplementedException (); }}

does anyone know what im doing wrong, or what i need to do instead of this?



  • I too need to know how to implement IFacebookCallback... is there any documentation anywhere for using Xamarin.Facebook because I can't find any and every article on SO differs, and doesn't work.

  • JoeHonourJoeHonour GBMember

    I have now changed it and am using Xamarin.Auth, works really well and good documentation on it. Would highly recommend changing to use that instead of the original Facebook package.

  • GrahamPettGrahamPett GBUniversity ✭✭

    You just need to inherit from Java.Lang.Object which will implement the Handle for you. Also, not sure what you're doing with the generics in the declaration, your class should just be declared like:

    public class FacebookLoginCallback : Java.Lang.Object, IFacebookCallback { ... }

Sign In or Register to comment.