Forums - C# Corner

Forum guidelines
Abou Mohamad

Abou Mohamad

  • 1.5k
  • 33
  • 2.5k

Retrieve Facebook pageId after authentication with facebook

Feb 13 2018 5:21 AM
dear;
 
i am working a website using mvc 5 c# language
 
i want to get the facebook page id managed by the user to get access to her page details and posts.
first step the user login with his facebook account and after authentication i can get access to her facebook access token, FBid, email and all user details but what i need is to get access to the pages managed by the authenticated user.
 
Please can anyone help me. followed a piece of code used.
 
var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
{
AppId = "My_APP_ID",
AppSecret = "My_APP_Secret",
Provider = new FacebookAuthenticationProvider()
{
OnAuthenticated = async ctx =>
{
ctx.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", ctx.AccessToken));
}
}
};
facebookAuthenticationOptions.Scope.Add("email");
facebookAuthenticationOptions.Scope.Add("user_posts");
facebookAuthenticationOptions.Scope.Add("user_birthday");
facebookAuthenticationOptions.Scope.Add("public_profile");
facebookAuthenticationOptions.Scope.Add("manage_pages");
facebookAuthenticationOptions.Scope.Add("pages_show_list");
string userprokey = Info.Login.LoginProvider; //get the user facebook ID)
var identity = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
var access_token = identity.FindFirstValue("FacebookAccessToken");
var fb = new FacebookClient(access_token);
dynamic uEmail = fb.Get("/me?fields=email");
dynamic uBirthDate = fb.Get("/me?fields=birthday");
dynamic uFname = fb.Get("/me?fields=first_name");
dynamic uLname = fb.Get("/me?fields=last_name");

Answers (2)

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now