Facebook gender is always null

I want to login with facebook to Backendless with the android SDK v4.5.1 and fetch some personal information. The fields birthday and first_name work but gender is always null. I tried the same with pure facebook SDK 4.34.0 and it worked as expected.
This is my backendless login (gender is null)

public void facebookLogin() {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_birthday", "user_photos", "user_gender", "public_profile"));
}



private void loginToBackendlessWithFacebook() {
Map<String, String> facebookFieldMappings = new HashMap<>();
facebookFieldMappings.put("first_name", UserProperty.USERNAME.getPropertyName());
facebookFieldMappings.put("birthday", UserProperty.BIRTHDAY.getPropertyName());
facebookFieldMappings.put("gender", UserProperty.GENDER.getPropertyName());



Backendless.UserService.loginWithFacebookSdk(fbAccessToken, facebookFieldMappings, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
setCurrentUserAndProceed(); // Here gender is null
}
@Override
public void handleFault(BackendlessFault fault) {
log.error("Could not backendlessLogin to facebook {}", fault.getMessage());
}
}, true);
}

This is the plain facebook request (gender is correct)

GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
System.out.println();
} catch (Exception e) {}}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name, email,gender,birthday,location");
request.setParameters(parameters);
request.executeAsync();
}

Any suggestions?

Thanks

Hi Kevin,

What is Backendless v4.5.1? Is this a Backendless Pro installation?

Regards,
Mark

Hi Mark,

sorry, this is the Backendless SDK version. I fixed it in the question.

Best regards

Hi Kevin,

What is the name of the property you map “gender” to in this line of code?:

facebookFieldMappings.put("gender", UserProperty.GENDER.getPropertyName());

Also, it was not clear to me why the naming of the properties is different here:

LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_birthday", "user_photos", "user_gender", "public_profile"));

from here:

parameters.putString("fields", "id, name, email,gender,birthday,location");

Shouldn’t it be the same since both requests go through FB sdk?

  1. The gender field maps to the property “gender” which is a column in my user table. The result from my enum is this:
facebookFieldMappings.put("gender", "gender");
  1. These are not the fields but the permissions I have to request from facebook to retrieve the fields. see https://developers.facebook.com/docs/facebook-login/permissions/#reference-user_gender
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_birthday", "user_photos", "user_gender", "public_profile"));
  1. These are the fields I want to get for the user.
parameters.putString("fields", "id, name, email,gender,birthday,location");

Thank you for the answers. One more question, is there the “gender” column in the “Users” table in your app? If there is, what is its data type?

Yes, it is a string. Please see the picture attached.

Thanks. Everything seems to be correct. I will open an internal ticket so this can be investigated further.

Regards,
Mark

Thank you very much for the help.

Best regards,
Kevin

For tracking purposes the internal ticket number is BKNDLSS-17218

Hi, Kevin. Did you try to generate “Registration and Login” example on “Code Gneration” section? Because it works for me perfectly.

Also notice, that the version you are using is too old.
Please look here for the new one (ex. 5.0.2 for now): http://mvnrepository.com/artifact/com.backendless/backendless

In addition i’ve tried with 4.5.1 version library. And all works.
Could you, please, try to perform the login with the old library but with code generated on “Code Gneration” section? It produces a simple example without any dependencies.

Hi,
I now tried it with the new library version 5.0.2 and the Code Generation example. But my facebook properties of the BackendlessUser are always null, if they are not already in the Users table, i.e. they are not fetched from facebook. Maybe I miss something. I try to figure it out. Thank you very much for your help, anyway!

Best regards