Login with Facebook on Xamarin Forms

0

I'm developing an application using Xamarin.Forms and need to use Facebook's authentication system. what happens is that when I debug it I get an error message saying:

  

Unable to load URL: The domain for this URL is not included   in the application domains. In order to load this URL, add   all domains and subdomains to the Application domains field in the   application settings.

The problem is that I do not know what URL I should by in this field. Here is the pageRenderer code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.Forms.Platform.Android;
using Xamarin.Auth;
using Newtonsoft.Json.Linq;
using Xamarin.Forms;
using GrowBox.Views;
using GrowBox.Droid;

[assembly: ExportRenderer (typeof (FacebookPage), typeof(LoginPageRenderer))]
namespace GrowBox.Droid
{
    public class LoginPageRenderer : PageRenderer
    {
        public LoginPageRenderer()
        {
            var activity = this.Context as Activity;
            var auth = new OAuth2Authenticator(
                clientId: "1978274929116582",
                scope: "",
                authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri("https://www.facebook.com/connect/login-sucess.html"));

            auth.Completed += async (sender, eventArgs) =>
            {
                if (eventArgs.IsAuthenticated)
                {
                    var accessToken = eventArgs.Account.Properties["access_token"].ToString();
                    var expireIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
                    var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expireIn);

                    var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null,
                        eventArgs.Account);
                    var response = await request.GetResponseAsync();
                    var obj = JObject.Parse(response.GetResponseText());

                    var id = obj["id"].ToString().Replace("\"", "");
                    var name = obj["name"].ToString().Replace("\"", "");
                    App.HideLoginView();
                    App.NavigateToMainViewPage();
                }
                else
                {

                }
            };
            activity.StartActivity(auth.GetUI(activity));
        }
    }
}
    
asked by anonymous 09.09.2017 / 18:43

1 answer

0

Place the following URL in the Valid OAuth redirect URIs field:

http://www.facebook.com/connect/login_success.html

    
10.09.2017 / 06:34