一切都习以为常,直到fb将api升级到2.4 (我以前的项目中有2.3).
今天当我在fb开发人员上添加一个新的应用程序时,我得到了api 2.4.
问题:现在我从fb(loginInfo.email = null)收到空电子邮件.
当然,我检查了用户电子邮件在fb配置文件中处于公共状态,
我去了loginInfo对象,但没有找到任何其他电子邮件地址.
我谷歌,但没有找到任何答案.
请任何帮助..我有点迷路..
谢谢,
我的原始代码(适用于2.3 api):
在AccountController.cs中:
//
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
//A way to get fb details about the log-in user:
//var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name"); <--worked only on 2.3
//var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:name"); <--works on 2.4 api …Run Code Online (Sandbox Code Playgroud) c# facebook facebook-graph-api asp.net-mvc-5 asp.net-identity-2
显然,您可以通过在以下FacebookAuthenticationOptions对象中添加范围来向Facebook提供商执行此操作Startup.Auth.cs:
List<string> scope = new List<string>() { "email" };
var x = new FacebookAuthenticationOptions();
x.Scope.Add("email");
...
app.UseFacebookAuthentication(x);
Run Code Online (Sandbox Code Playgroud)
如何与Google提供商进行相同的操作?类/对象没有x.Scope属性GoogleAuthenticationOptions!
我知道提供了"名称"字段,但我更愿意明确地访问名字和姓氏.有人可以帮忙吗?我仍然围绕着ASP.Net MVC.
我们的Facebook登录目前无效.我们收到了Facebook Developer Portal的消息:
"应用程序名称"目前可以访问Graph API v2.2,该版本将于2017年3月27日达到其2年生命周期的终点.为确保平稳过渡,请将所有调用迁移到Graph API v2.3或更高版本.
要检查您的应用是否会受到此升级的影响,您可以使用版本升级工具.这将显示哪些呼叫(如果有)受此更改影响以及更新版本中的任何替换呼叫.如果您没有看到任何电话,则您的应用可能不会受到此更改的影响.
您还可以使用我们的更改日志查看所有Graph API版本中的完整更改列表.
我们正在使用ASP.NET MVC 5,我们正在使用或认证如下:
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "****",
AppSecret = "****",
AuthenticationType = "Facebook",
SignInAsAuthenticationType = "ExternalCookie",
Provider = new FacebookAuthenticationProvider
{
OnAuthenticated = async ctx => ctx.Identity.AddClaim(new Claim(ClaimTypes.Email, ctx.User["email"].ToString()))
}
};
facebookAuthenticationOptions.Scope.Add("email");
Run Code Online (Sandbox Code Playgroud)
但今天,我们的登录信息对象在ExternalLoginCallback中为null:
[HttpGet]
[AllowAnonymous]
[RequireHttps]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl = null)
{
try
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
... more code here...
Run Code Online (Sandbox Code Playgroud)
在Facebook开发.Portal我们的API版本是2.3 …