I am using Facebook SDK to get email of user. I write this code in Startup.Auth.css class :
var x = new FacebookAuthenticationOptions();
x.Scope.Add("email");
x.AppId = "421656951358309";
x.AppSecret = "5a2e5ccf163fe6918b6d6fdc8dda5184";
x.Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = async context =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
}
};
x.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
app.UseFacebookAuthentication(x);
And in controller, I use two method to get email but both methods fail. Here is the methods :
Method 1 : By default, after executing the first line the variable info has email property. But it always return null.
var info = await AuthenticationManager.GetExternalLoginInfoAsync();
string email = info.Email;
Method 2 : I use the following code, it also return null.
var fb = new FacebookClient(access_token.Value);
dynamic me = fb.Get("email");
string email = me.email;
Did I miss something ? or there is another method that I can use. I can get others information such as username, but for email I can't.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire