0

I have an issue with grabbing facebook user details from my MVC web application. I want to grab the age_range value (which is public value and is included public_profile) or the user_birthday value, which is giving it's value only to the app administrator.

var x = new FacebookAuthenticationOptions();
            x.Scope.Add("user_birthday");
            x.Scope.Add("email");
            x.Scope.Add("public_profile");
            x.Scope.Add("user_friends");
            x.Scope.Add("age_range");

            x.AppId = "....";
            x.AppSecret = "....";
            x.Provider = new FacebookAuthenticationProvider()
            {
                OnAuthenticated = async context =>
                {
                    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);
                        string claimValue = claim.Value.ToString();
                        if (!context.Identity.HasClaim(claimType, claimValue))
                            context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
                    }
                }
            };

            x.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
            app.UseFacebookAuthentication(x);

and another code chunk, which is grabbing the values.

var firstNameClaim = info.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name");
                var lastNameClaim = info.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:last_name");
                var DOBClaim = info.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:birthday");
                var ageRange = info.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:age_range");

So can anyone help me to grab the user age_range value ??

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
UnuS76
  • 149
  • 1
  • 13
  • very glad to hear what it is you want.. but where is the real question here.. what issue are you having what line or lines are causing you errors..? please state the following – MethodMan Jan 26 '15 at 21:57
  • Hi @MethodMan, I want to grab the birthdate value, or age_range value. One of this two values, which I can't do now. I can't get the age_range of user. – UnuS76 Jan 26 '15 at 21:59
  • 1
    Refer this [Answer](http://stackoverflow.com/a/25967936/3266029) – tom Jan 27 '15 at 12:00
  • Thanks @tom for you help, but I've already seen that answer , and unfortunately it didn't help me. – UnuS76 Jan 29 '15 at 06:58

0 Answers0