加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 03:35:38 所属栏目:asp.Net 来源:网络整理
导读:我们的Facebook登录目前无效.我们收到了Facebook Developer Portal的消息: “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 a
我们的Facebook登录目前无效.我们收到了Facebook Developer Portal的消息:

“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中为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...

在Facebook开发. Portal我们的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 Pacakges进行更新

> 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);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读