Search code examples
c#asp.netasp.net-mvcoauth-2.0facebook-oauth

how to get first_name and last_name from facebook OAuth in MVC 5.0 C#?


I need to get first_name and last_name from Facebook v2_5 OAuth. in C#, MVC 5.I am using Microsoft.Owin.Security.Facebook 3.0.1.0.

`var record = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:name");`

I am getting name by using this, but I need first_name and last_name separately. Any help will be appreciated.Thanks in advance.


Solution

  • It´s called "Declarative Fields", see changelog for v2.4: https://developers.facebook.com/docs/graph-api/changelog/archive#v2_4_new_features

    This would be the API call to get first_name and last_name:

    /me?fields=name,first_name,last_name