我遇到了从我的MVC网络应用程序中获取Facebook用户详细信息的问题。我想获取age_range值(它是公共值并包含在public_profile中)或user_birthday值,它只向应用程序管理员提供它的值。
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);
和另一个代码块,它正在抓取值。
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");
所以任何人都可以帮我抓住用户age_range值吗?