Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Facebook login failed in XAMARIN webview

progmaticprogmatic USMember

I am making webview of working website, but in the webview the facebook login doesn't work. I enter email, pass, and when i click sign in, it retries me to the login page.. Someone help me. Here is my code:

WebView web_view;

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

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);
    web_view = FindViewById<WebView>(Resource.Id.webview);
    web_view.Settings.JavaScriptEnabled = true;

    var cookieManager = CookieManager.Instance;
    cookieManager.SetAcceptCookie(true);

    web_view.SetWebViewClient(new HelloWebViewClient());
    web_view.LoadUrl("[MY LINK]");

}


public override bool OnKeyDown(Keycode keyCode, Android.Views.KeyEvent e)
{
    if (keyCode == Keycode.Back && web_view.CanGoBack())
    {
        web_view.GoBack();
        return true;
    }

    return base.OnKeyDown(keyCode, e);
}


public class HelloWebViewClient : WebViewClient
{

    public override bool ShouldOverrideUrlLoading(WebView view, string url)
    {
        Uri uri = new Uri(url);

        var cookieManager = CookieManager.Instance;
        var cookieContainer = new CookieContainer();
        cookieContainer.GetCookies(uri);
        cookieManager.SetAcceptCookie(true);
        cookieManager.RemoveAllCookie();
        view.Settings.JavaScriptEnabled = true;
        Console.WriteLine("{0}", url);
        return false;
    }
}

}

Answers

Sign In or Register to comment.