asp.net-mvc - 弃用版本 Facebook Graph API v2.2

标签 asp.net-mvc facebook facebook-graph-api asp.net-mvc-5

我们的 Facebook 登录目前无法使用。我们收到了来自 Facebook 开发者门户的消息:

"Name of app" currently has access to Graph API v2.2 which will reach the end of its 2-year lifetime on 27 March, 2017. To ensure a smooth transition, please migrate all calls to Graph API v2.3 or higher.

To check if your app will be affected by this upgrade you can use the Version Upgrade Tool. This will show you which calls, if any, are affected by this change as well as any replacement calls in newer versions. If you do not see any calls, your app may not be affected by this change.

You can also use our changelog to see the full list of changes in all Graph API versions.

我们正在使用 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");

但是今天,我们的登录信息对象在 ExternalLoginCallback 中为空:

        [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...

在 Facebook 开发中。门户我们的 API 版本是 2.3

我们测试了很多选项,但没有结果:

Access email address in the OAuth ExternalLoginCallback from Facebook v2.4 API in ASP.NET MVC 5

Why new fb api 2.4 returns null email on MVC 5 with Identity and oauth 2?

非常感谢您的帮助。

最佳答案

我遇到了同样的问题,下面是我如何设法解决它并从 Facebook 收到电子邮件。

  • 更新以下 NuGet 包
    • Microsoft.Owin 至版本 3.1.0-rc1
    • Microsoft.Owin.Security 到版本 3.1.0-rc1
    • Microsoft.Owin.Security.Cookies 到版本 3.1.0-rc1
    • Microsoft.Owin.Security.OAuth 到版本 3.1.0-rc1
    • Microsoft.Owin.Security.Facebook 到版本 3.1.0-rc1

然后在Identity Startup类中添加如下代码

var facebookOptions = new FacebookAuthenticationOptions()
        {
            AppId = "your app id",
            AppSecret = "your app secret",
            BackchannelHttpHandler = new FacebookBackChannelHandler(),
            UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email,first_name,last_name",
            Scope = { "email" }
        };

        app.UseFacebookAuthentication(facebookOptions);

这是 FacebookBackChannelHandler() 的定义类:

using System;
using System.Net.Http;

public class FacebookBackChannelHandler : HttpClientHandler
{
    protected override async System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(
        HttpRequestMessage request,
        System.Threading.CancellationToken cancellationToken)
    {
        // Replace the RequestUri so it's not malformed
        if (!request.RequestUri.AbsolutePath.Contains("/oauth"))
        {
            request.RequestUri = new Uri(request.RequestUri.AbsoluteUri.Replace("?access_token", "&access_token"));
        }

        return await base.SendAsync(request, cancellationToken);
    }
}

关于asp.net-mvc - 弃用版本 Facebook Graph API v2.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43058355/

相关文章:

facebook-graph-api - "Like"使用 Facebook Graph API 的页面, objective-c

asp.net-mvc - 寻求 '=>' 运算符的概述

asp.net - ASP 5 MVC 6 - 优点和缺点 : multiple web api services - use one or more projects?

asp.net-mvc - 如何从 ValidationAttribute 内部获取模型元数据?

java - Facebook 的 Spring Social - 获取用户位置

javascript - Facebook Javascript SDK - 未安装我的应用程序的带有图片的好友列表

java - 如何在 Facebook SDK 中将字符串访问 token 转换为 AccessToken 对象

c# - 如何使智能感知与 RazorEngine 一起工作?

ios - 使用社交框架通过 iOS 6 应用程序共享内容说 iOS 设备?

javascript - 如何制作Facebook剧院 View