Oauth.facebook.Fields

How can I get all of the data fields from Facebook? All I’ve managed to get is firstname, lastname, id and email. I thought I could do something like:

<add key="oauth.facebook.Fields" value="id,name,first_name,last_name,email,cover,name,age_range,link,gender,locale,picture,timezone,updated_time,verified" />
<add key="oauth.facebook.Permissions" value="email,public_profile,user_about_me,user_birthday,user_location" />

but no matter what I do I only get the same few fields.

What do you mean by “get same few fields”, get where? Do you mean populated on your AuthUserSession?

You can either create a custom FacebookAuthProvider that overrides LoadUserAuthInfo and extract the info you want.

Or implement OnAuthenticated in a Session or Auth Event and extract other info in authInfo on your Custom AuthUserSession.

I have created a CustomUserSession class. In this class I override OnAuthenticated (like in the SocialBootstapAPI).
I have code like the following:

        var appSettings = authService.TryResolve<IAppSettings>();
        var userAuthRepo = authService.TryResolve<IAuthRepository>();
        var userAuth = userAuthRepo.GetUserAuth(session, tokens);
        var dbConnectionFactory = authService.TryResolve<IDbConnectionFactory>();
        foreach (var authTokens in session.ProviderOAuthAccess)
        {
            if (authTokens.Provider == FacebookAuthProvider.Name)
            {
              ...

If I check authTokens I find that I can get id, email, first_name, last_name, username (same as id) and Display Name (which is First and last name). I added permissions and I do get the correct prompt from Facebook based on those permissions:

<add key="oauth.facebook.Permissions" value="email,public_profile,user_about_me,user_birthday,user_location" />

but when I check authTokens I still only have data for id, email, first_name, last_name, username.
In the Facebook oath provider you have:

 public static string[] DefaultFields = { "id", "name", "first_name", "last_name", "email" };

it seems to be the only fields that are ever returned.
I tried to figure out how to set this property. It seems like:

 <add key="oauth.facebook.Fields" value="id,name,first_name,last_name,email,cover,name,age_range,link,gender,locale,picture,timezone,updated_time,verified" />

should work based on the way the other properties are set, but that actually seems to keep it from working at all.
I tried to figure out how to set that property in code but I don’t think I set it in the right place.
I tried this against my personal Facebook account where the majority of those fields contain data.

After you Sign In, you can use the AccessToken in UserAuthDetails table with this url to test what Facebook APIs return:

https://graph.facebook.com/v2.8/me?access_token={0}&fields={fields}

Or by using their Graph API Explorer: https://developers.facebook.com/tools/explorer

There’s an error here where you’ve specified name twice which causes the API Request to fail:

 <add key="oauth.facebook.Fields" value="id,name,first_name,last_name,email,cover,name,age_range,link,gender,locale,picture,timezone,updated_time,verified" />

After removing duplicate name:

 <add key="oauth.facebook.Fields" value="id,name,first_name,last_name,email,cover,age_range,link,gender,locale,picture,timezone,updated_time,verified" />

And now I feel like a complete dumb ass. After removing the duplicate field everything works exactly like it should.

1 Like