版本弃用Facebook Graph API v2.2 [英] Version Deprecation Facebook Graph API v2.2

查看:293
本文介绍了版本弃用Facebook Graph API v2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的Facebook登录现在不起作用。我们收到了Facebook开发人员门户的消息:

our Facebook Login is not working right now. We have received a message from Facebook Developer Portal:


应用程序名称目前可以访问Graph API v2.2,它将到达为了确保平稳过渡,
请将所有调用转移到Graph API v2.3或更高版本。

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

您还可以使用我们的更改日志查看完整的更改列表在
Graph API版本中。

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

我们正在使用ASP.NET MVC 5,我们正在使用或认证:

We are using ASP.NET MVC 5, and we are using or authentication like this:

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:

But today, our login info object, is null in 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开发。 Portal我们的API版本是2.3

In Facebook Dev. Portal our API Version is 2.3

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

We have tested many options, with no results:

来自Facebook v2的OAuth ExternalLoginCallback中的访问电子邮件地址.4 ASP.NET MVC 5中的API

为什么新的fb api 2.4在MVC 5上使用Identity和oauth 2返回null电子邮件? >

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

非常感谢您的帮助。

推荐答案

同样的问题,这里是我如何设法解决它,并从Facebook获取电子邮件。

I had the same problem and here is how I managed to fix it and get the email from Facebook.


  • 更新以下NuGet Pacakges


    • Microsoft.Owin 到版本 3.1.0-rc1 / li>
    • 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 / li>
    • Update following NuGet Pacakges
      • Microsoft.Owin to version 3.1.0-rc1
      • Microsoft.Owin.Security to version 3.1.0-rc1
      • Microsoft.Owin.Security.Cookies to version 3.1.0-rc1
      • Microsoft.Owin.Security.OAuth to version 3.1.0-rc1
      • Microsoft.Owin.Security.Facebook to version 3.1.0-rc1

      然后将以下代码添加到 Identity Startup class

      Then add the following code to the Identity Startup class

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

      这篇关于版本弃用Facebook Graph API v2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆