用户电子邮件未通过Facebook登录返回

dis*_*kid 2 c# facebook winforms facebook-graph-api

我试图通过我的应用程序中的Facebook登录页面访问用户的信息WinForm.即使我要求用户email使用扩展权限,我提交的所有内容都是名称和ID.

public partial class Form1 : Form
{
    private const string AppId = "MY_APP_ID_IS_HERE";
    private Uri loginUrl;
    private const string extendedPermissions = "public_profile,user_friends,email";
    FacebookClient fbClient = new FacebookClient();
    private string _accessToken;
    private bool _authorized;
    private string _currentName;
    private string _currentEmail;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Login();
    }

    private void Login()
    {
        dynamic parameters = new ExpandoObject();
        parameters.client_id = AppId;
        parameters.redirect_uri = "https://www.facebook.com/connect/login_success.html";
        parameters.response_type = "token";
        parameters.display = "popup";
        if (!string.IsNullOrWhiteSpace(extendedPermissions))
            parameters.scope = extendedPermissions;
        var fb = new FacebookClient();
        loginUrl = fb.GetLoginUrl(parameters);
        webBrowser1.Navigate(loginUrl.AbsoluteUri);
    }

    private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
    {
        if (webBrowser1.Visible)
        {
            var fb = new FacebookClient();
            FacebookOAuthResult oauthResult;
            if (fb.TryParseOAuthCallbackUrl(e.Url, out oauthResult))
            {
                if (oauthResult.IsSuccess)
                {
                    _accessToken = oauthResult.AccessToken;
                    _authorized = true;
                }
                else
                {
                    _accessToken = "";
                    _authorized = false;
                }
                if (_authorized)
                {
                    fb = new FacebookClient(_accessToken);
                    dynamic result = fb.Get("me");
                    _currentName = result.name;
                    _currentEmail = result.email;
                    lblLoggedInUser.Text = string.Format("Facebook User: {0}", _currentName);
                    lblPassword.Text = string.Format("Email: {0}", _currentEmail);
                    //Do what need being done now that we are logged in!
                }
                else
                {
                    MessageBox.Show("Couldn't log into Facebook!", "Login unsuccessful", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

当我运行查询并使用Facebook Graph API Explorer询问用户的电子邮件时,它会返回以下调试消息: 在此输入图像描述

显然我的程序并没有要求允许使用用户的电子邮件.因为在我提交登录后立即显示带有"成功"文本的白页,并且不返回电子邮件的值.

如何更改登录页面以询问用户的电子邮件?

Tob*_*obi 7

尝试

dynamic result = fb.Get("me?fields=id,name,email");
Run Code Online (Sandbox Code Playgroud)