如何在asp.net MVC 5中从facebook图形版本V 2.4中检索个人资料照片,电子邮件

时间:2015-08-19 05:24:08

标签: asp.net-mvc-5 facebook-graph-api-v2.4

我需要facebook的个人资料照片和电子邮件,目的是asp.mvc 5 web应用程序。但Facebook图形api版本2.4电子邮件权限访问。但.net mvc 5代码电子邮件值为null。和个人资料照片。

startup.Auth

   var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
        {
            AppId = "1655122338065609",
            AppSecret = "5e858655ce82fad864e3991ae00db87a"
        };
        facebookAuthenticationOptions.Scope.Add("email");

        app.UseFacebookAuthentication(facebookAuthenticationOptions);

ExternalLoginCallback

 public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

        var externalIdentity = HttpContext.GetOwinContext().Authentication.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
        var emailClaim = externalIdentity.Result.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email);

        var email = emailClaim.Value;



        // Sign in the user with this external login provider if the user already has a login
        var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { UserName=loginInfo.DefaultUserName,Email=loginInfo.Email });
        }
    }

externallogoncallbacck方法 var emailcliam 值从startup.auth返回null ???

0 个答案:

没有答案