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

Something has changed from facebook v2.3 APIs to v2.4 - after using 2.4 I can only get the name and ID,

I saw several posts about adding "? Fields = scopes ...", but for me it was a real mystery - I'm trying to figure out how to send these field fields ...

Here is my code:

var facebookAuthOptions = new FacebookAuthenticationOptions(); facebookAuthOptions.AppId = facebookAuthAppId; facebookAuthOptions.AppSecret = facebookAuthAppSecret; facebookAuthOptions.Scope.Add("email"); facebookAuthOptions.Scope.Add("user_birthday"); facebookAuthOptions.Scope.Add("public_profile"); facebookAuthOptions.Provider = new FacebookAuthenticationProvider() { OnAuthenticated = (context) => { // https://stackoverflow.com/questions/25966530/asp-net-mvc-5-1-c-sharp-owin-facebook-authentication-or-login-ask-for-birthday/25967936#25967936 context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken)); foreach (var claim in context.User) { var claimType = string.Format("urn:facebook:{0}", claim.Key); var claimValue = claim.Value.ToString(); if (!context.Identity.HasClaim(claimType, claimValue)) context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook")); } return Task.FromResult(0); } }; app.UseFacebookAuthentication(facebookAuthOptions); 

Thanks in advance.

UPDATE 1: I tried to enter the scope fields as follows:

 facebookAuthOptions.UserInformationEndpoint += "?fields=email,user_birthday,first_name,last_name"; 

But still not working ...

UPDATE 2: I found this post that allows you to receive email, but I need to install an additional Facebook SDK for .NET , which I prefer to avoid ... also found this post that shows how to extract more values, like birthday ( in facebook API v4.3 I had to send a birthday, not user_birthday) dynamic myInfo = fb.Get ("/ me? fields = email, birthday"); I'm still looking for a way to send region values ​​using standard Oauth2 methods ...

UPDATE 3: I managed to get more information using the .NET.NET SDK - stack overflow.site/questions/89132 / ... But still prefer not to do this with the standard Oauth2 (and Owin) without using the .NET.NET SDK. ..

+3
facebook owin
Aug 09 '15 at 23:47
source share
2 answers

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

So maybe I can save another 6 hours :-)

You will need to install the Facebook SDK for .NET.

Here 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: now also need to be passed to appsecret_proof (added to the fragment)

+1
Aug 21 '15 at 8:48
source share

Facebook made some changes to 2.4. By default, you only get these two fields by default, if you need other fields that you must explicitly request from them:

Declarative fields To improve performance on mobile networks, Nodes and Edges in version 2.4 require that you explicitly request the fields that you need for your GET requests. For example, GET / v2.4 / me / feed no longer includes default preferences and comments, but GET / v2.4 / me / feed? Fields = comments-likes will return data. For more information, see Documents on How to Request Specific Fields.

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

Unfortunately, I'm not sure how to translate this for the library you are using.

+1
Aug 10 '15 at 7:38
source share



All Articles