使用 Xamarin.Auth 和 Facebook 身份验证获取电子邮件地址

Get email address with Xamarin.Auth and Facebook authentication

我有以下代码来尝试连接验证器

        var auth = new OAuth2Authenticator (
            appId,
            "email",
            new Uri ("https://m.facebook.com/dialog/oauth/"),
            new Uri ("http://www.facebook.com/connect/login_success.html"));

当对话框显示时,我可以看到它正在请求查看我的电子邮件的权限。但是我如何从服务中获取该电子邮件?

我进行以下调用以获取 Facebook ID

var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, args.Account);
                request.GetResponseAsync ().ContinueWith (t => {
                    var obj = JsonValue.Parse (t.Result.GetResponseText ());
                    var id = obj ["id"];
                });

但是我得到的回复中没有邮件。如何获取用户的电子邮件地址?

最新的 API 版本(撰写本文时为 2.4)使用声明字段,因此您需要像这样明确请求电子邮件字段:

https://graph.facebook.com/me?fields=email