Facebook OAuth Xamarin 表单重定向

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

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 登录插件创建应用程序。 将重定向 URL 添加为 http://www.facebook.com/connect/login_success.html

最佳答案

更新: 以下代码有效

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

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

关于Facebook OAuth Xamarin 表单重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42936310/

相关文章:

Azure APIM 根据两个不同的声明验证 JWT

android - 从 iOS 应用程序使用 OAuth 2.0 登录微博?

javascript - 从另一个 JavaScript 文件中获取 JavaScript 文件中的变量

javascript - 响应未定义/到达太晚 - Facebook API FB.api

android - 是否有 facebook api 用于查找通过我的应用程序注册的所有用户

ios - Xamarin iOS 设计器 : There was a error rendering this document

android - 如何在 Xamarin 中为谷歌地图实现标记聚类

android - 回收位图不释放内存

php - 发布到 FB 粉丝页面时如何修复 "Unsupported post request"?

scala - 使用Akka-Http进行身份验证