Click on Loginbutton facebook on android using Xamarin with Facebooksdk nothing happens

Asked

Viewed 311 times

22

I’m using Xamarin to try to log in with facebook, I already generated the Hash and appid. ( Apparently correct, because previously the app returned me an msg saying that the HASH was invalid ). Follow the code of my Activity:

    protected override void OnResume()
    {
        base.OnResume();
        // Logs 'install' and 'app activate' App Events.
        AppEventsLogger.ActivateApp(this);
    }
    /// <summary>
    /// Register events logs of the facebook
    /// </summary>
    protected override void OnPause()
    {
        base.OnPause();
        AppEventsLogger.DeactivateApp(this);
    }
    public override View OnCreateView(View parent, string name, Context context, IAttributeSet attrs)
    {
        return base.OnCreateView(parent, name, context, attrs);
    }
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        FacebookSdk.SdkInitialize(this.ApplicationContext);
        SetContentView(Resource.Layout.splash);



        var callbackmanage = CallbackManagerFactory.Create();
        LoginButton loginbutton = (LoginButton) base.FindViewById(Resource.Id.login_button);
        var fcb = new facebookCallBack();

        loginbutton.RegisterCallback(callbackmanage,fcb);


    }

    private class facebookCallBack : IFacebookCallback
    {
        public IntPtr Handle
        {
            get
            {
                return new IntPtr();
            }
        }

        public void Dispose()
        {
        }

        public void OnCancel()
        {

        }

        public void OnError(FacebookException p0)
        {

        }

        public void OnSuccess(Java.Lang.Object p0)
        {

        }
    }

It turns out that now when I click the login button, nothing happens. It does not give any error message, nor does it enter callback methods ( OnError, OnPause etc), gives absolutely nothing.

That way, I’m lost. Anyone can help?

  • 1

    You didn’t put anything in the methods that implementam IFacebookCallback how will you capture the return? See this example: https://gist.github.com/rmenezes/d1a98e18f19c6555c6c2

  • Thanks for the return. But I had put in the debug, breakpoint in all methods I implemented from Ifacebookcallback. None of them paused. I’ll check the example!

1 answer

1

You need at least one line of code within the method for breakpoint to enter. Place a log line and place the breakpoint on the log line.

private class facebookCallBack : IFacebookCallback
{
    public IntPtr Handle
    {
        get
        {
            return new IntPtr();
        }
    }

    public void Dispose()
    {
        Console.WriteLine("Teste Dispose");
    }

    public void OnCancel()
    {
        Console.WriteLine("Teste OnCancel");
    }

    public void OnError(FacebookException p0)
    {
        Console.WriteLine("Teste OnError");
    }

    public void OnSuccess(Java.Lang.Object p0)
    {
        Console.WriteLine("Teste OnSuccess");
    }
}

Try...

Replace the Appeventslogger.Activateapp(this); for AppEventsLogger.ActivateApp(getApplication()); and put that line on void Oncreate.

Move the Appeventslogger.Deactivateapp(this); to the void Ondestroy.

If it works from a feedback.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.