首页 文章

Facebook OAuth Xamarin表单重定向

提问于
浏览
7

enter image description here

我正在使用xamarin表单OAuth2登录Facebook,Google和Twitter .

在Android上它的工作原理 . 但在iOS上,屏幕会在右上角的旋转活动指示器处冻结 . 有没有人有同样的问题?

更新:请在下面找到代码

partial void UIButton15_TouchUpInside(UIButton sender)
{
    // https://developers.facebook.com/apps/
    var auth = new OAuth2Authenticator(
    clientId: "ID",
    scope: "",
    authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
    redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));

    var ui = auth.GetUI();

    auth.Completed += FacebookAuth_Completed;

    PresentViewController(ui, true, null);
}

async void FacebookAuth_Completed(object sender, AuthenticatorCompletedEventArgs e)
{
    if (e.IsAuthenticated)
    {
        var request = new OAuth2Request(
            "GET",
            new Uri("https://graph.facebook.com/me?fields=name,picture,cover,birthday"),
            null,
            e.Account);

        var fbResponse = await request.GetResponseAsync();
        var fbUser = JsonValue.Parse(fbResponse.GetResponseText());
        var name = fbUser["name"];
        var id = fbUser["id"];
        var picture = fbUser["picture"]["data"]["url"];
        var cover = fbUser["cover"]["source"];
    }
    DismissViewController(true, null);
}

在Facebook开发者网站上:

使用Facebook登录插件创建应用程序 . 添加重定向网址为http://www.facebook.com/connect/login_success.html

1 回答

  • 0

    UPDATED : 下面的代码有效

    PresentViewController(auth.GetUI(),true,false);

    似乎问题只发生在最新的OAuth库中 . 由于构建错误,无法使用以前版本的OAuth构建 . 因此创建了基于Webview的登录,然后是Graph API Request .

相关问题