【问题标题】:Facebook OAuth Xamarin Forms RedirectionFacebook OAuth Xamarin 表单重定向
【发布时间】:2017-08-13 15:53:09
【问题描述】:

我正在使用 xamarin 表单 OAuth2 登录 Facebook、Google 和 Twitter。

在安卓上它可以工作。但在 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

【问题讨论】:

  • 您使用的是哪个版本的 Xamarin.Auth?日志控制台中是否还显示任何错误/消息?
  • 感谢您的评论。控制台上没有错误消息。我正在使用 1.3.0。还尝试了最新的 1.3.2.7。
  • 更新显示您用于通过 facebook 进行身份验证的代码的帖子
  • 有点长镜头,但重定向 URL 是 http URL。 iOS默认不再允许这些,您可以将其更新为https或在您的info.plist文件中实现NSAppTransportSecurity键。
  • 尝试将这些行修改为:RootView.PresentViewController(auth .GetUI(), true, null); RootView.DismissViewController(true, null);

标签: facebook xamarin oauth-2.0 xamarin.ios xamarin.forms


【解决方案1】:

更新: 下面的代码有效

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

似乎只有最新的 OAuth 库才会出现问题。由于构建错误,无法使用以前版本的 OAuth 构建。因此创建了基于 Webview 的登录,然后是 Graph API 请求。

【讨论】:

    猜你喜欢
    • 2011-05-27
    • 2011-09-23
    • 2012-07-10
    • 2020-04-28
    • 2012-03-31
    • 1970-01-01
    • 1970-01-01
    • 2014-12-04
    • 2011-07-12
    相关资源
    最近更新 更多