2
回到我试图通过一个的Facebook登录页面访问用户的信息在我的WinForm
应用。即使我要求用户在email
扩展权限,我得到后提交的名称和编号。用户电子邮件没有通过Facebook登录
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);
}
}
}
}
}
当我运行查询,并要求使用Facebook的图形API浏览器用户的电子邮件,它返回调试消息:
显然,我的程序不要求使用用户的电子邮件的权限。因为在我提交我的登录信息后立即显示带有“成功”文本的白页,并且没有返回任何电子邮件值。
我怎样才能改变我的登录页面,要求用户的电子邮件?
谢谢!现在工作。 – Disasterkid
令人惊叹;感谢Tobi!今天早上我一直在用这个甩掉我的头! –