Facebook v2.4 with OAuth2 stopped working and only getting name and id

落花浮王杯 提交于 2019-12-05 21:47:38

Facebook made some changes in 2.4. You only get those two fields by default now, if you want any other fields you have to explicitly request them:

Declarative Fields To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

https://developers.facebook.com/docs/apps/changelog#v2_4_changes

Unfortunately I'm not sure how to translate that for the Library that you're using.

SOLVED! finally... and working with the new facebook APIs v2.4

So maybe I can save someone else 6 hours :-)

You will need to install Facebook SDK for .NET

This is how I fixed it:

// Use Facebook SDK for .NET to get more specific data (https://github.com/facebook-csharp-sdk/facebook-csharp-sdk)

var identity = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
var facebookAccessToken = identity.FindFirstValue("FacebookAccessToken");
var fb = new FacebookClient(facebookAccessToken);

dynamic facebookInfo = fb.Get("/me?appsecret_proof=YourFacebookAppSecretProof&fields=email,birthday,gender");
signInInfo.Email = facebookInfo.email;

UPDATE: it is now also required to pass in the appsecret_proof (added to the snippet)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!