facebook Xamarin.Auth活动重定向器

时间:2018-11-29 21:06:09

标签: android facebook url-redirection xamarin.auth

我尝试在Xamarin应用程序中添加facebook身份验证(Google已经完成)

在facebook上,我将https://www.facebook.com/connect/login_success.html添加为URI,以便重定向OAuth有效,我的所有auth参数都已启用。

在Xamarin上:

public static string AndroidRedirectUrl = "https://www.facebook.com/connect/login_success.html"

在Constants_Facebook类中,

点击时:

          string clientId = null;
            string redirectUri = null;

            if (Device.RuntimePlatform == Device.iOS)
            {
                clientId = Constants_Facebook.iOSClientId;
                redirectUri = Constants_Facebook.iOSRedirectUrl;
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                clientId = Constants_Facebook.AndroidClientId;
                redirectUri = Constants_Facebook.AndroidRedirectUrl;
            }

            var AuthorizeUrl = new Uri(Constants_Facebook.AuthorizeUrl);
            var AndroidRedirectUrl = new Uri(Constants_Facebook.AndroidRedirectUrl);
            var AccessTokenUrl = new Uri(Constants_Facebook.AccessTokenUrl);

            var authenticator = new OAuth2Authenticator(
                clientId,
                string.Empty,
                Constants_Facebook.Scope,
                AuthorizeUrl,
                AndroidRedirectUrl,
                AccessTokenUrl,
                null,
                true);

            authenticator.Completed += OnAuthCompleted_fb;

            AuthenticationState.Authenticator = authenticator;

            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
            presenter.Login(authenticator);

Android部分的活动:

[Activity(Label = "ActivityCustomUrlSchemeInterceptor", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter
    (
    actions: new[] { Intent.ActionView },
    Categories = new[]
            {
                Intent.CategoryDefault,
                Intent.CategoryBrowsable
            },
    DataScheme = "https",
    DataHost = "www.facebook.com",
    DataPath = "/connect/login_success.html"
    )]

在应用程序上,登录后,我只会看到

Success , warning message about safety

所以我认为问题出在我的意图过滤器声明中或在Facebook部分

有人有主意吗?

1 个答案:

答案 0 :(得分:0)

我认为Xamarin.auth或Facebook上存在问题:

var authenticator = new OAuth2Authenticator(
            clientId,
            string.Empty,
            Constants_Facebook.Scope,
            AuthorizeUrl,
            AndroidRedirectUrl,
            AccessTokenUrl,
            null,
            false);

使用本机UI无法正常工作。