我正在尝试手动使用Facebook API构建Login。我正在使用https://www.nuget.org/packages/Facebook/&在我的ASP.NET MVC中使用以下代码。
基本思想是询问用户权限,访问用户电子邮件,自动注册到我的系统。
问题是当用户取消对电子邮件和电子邮件的访问权限时在facebook身份验证弹出窗口中单击“确定”。下次用户点击"使用Facebook登录"按钮,Facebook身份验证弹出窗口不会显示,因为用户已经允许访问,我不会收到用户的电子邮件。唯一的方法是重新显示facebook身份验证框,用户可以通过个人脸书帐户撤销对我的应用的访问权限。
还有另外一种方法,我可以再次获得facebook身份验证弹出窗口吗?还是更好的方法呢?
var fb = new FacebookClient();
dynamic result = fb.Post("oauth/access_token", new
{
client_id = System.Configuration.ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = System.Configuration.ConfigurationManager.AppSettings["FacebookAppSecret"],
redirect_uri = System.Configuration.ConfigurationManager.AppSettings["FacebookRedirectURL"],
code = code
});
var accessToken = result.access_token;
// Store the access token in the session
Session["AccessToken"] = accessToken;
// update the facebook client with the access token so
// we can make requests on behalf of the user
fb.AccessToken = accessToken;
// Get the user's information
dynamic me = fb.Get("me?fields=first_name,last_name,id,email");
if (!String.IsNullOrWhiteSpace(me.email))
{
string email = me.email;
// Register Or login user
}
else
{
// Handle declined email permissions
}