Login with Facebook at Xamarin Forms

Asked

Viewed 614 times

1

I am developing an App using Xamarin.Forms and I need to use the Facebook authentication system. what happens is that when I debug it I get an error message saying:

Unable to load URL: The domain of that URL is not included in the application domains. To load this URL, add all domains and subdomains to the Application Domains field in application settings.

The problem is that I don’t know which URL I should put in this field. Follow 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));
        }
    }
}

1 answer

1

Put the following URL in the field Valid Oauth redirect uris:

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

Imagem mostrando a tela de configuração da aplicação no Facebook

Browser other questions tagged

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