Backendless Support
 
Waiting for user's response

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)

  1. public void facebookLogin() {
  2. LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_birthday", "user_photos", "user_gender", "public_profile"));
  3. }
  4. private void loginToBackendlessWithFacebook() {
  5. Map<String, String> facebookFieldMappings = new HashMap<>();
  6. facebookFieldMappings.put("first_name", UserProperty.USERNAME.getPropertyName());
  7. facebookFieldMappings.put("birthday", UserProperty.BIRTHDAY.getPropertyName());
  8. facebookFieldMappings.put("gender", UserProperty.GENDER.getPropertyName());
  9. Backendless.UserService.loginWithFacebookSdk(fbAccessToken, facebookFieldMappings, new AsyncCallback<BackendlessUser>() {
  10. @Override
  11. public void handleResponse(BackendlessUser response) {
  12. setCurrentUserAndProceed(); // Here gender is null
  13. }
  14. @Override
  15. public void handleFault(BackendlessFault fault) {
  16. log.error("Could not backendlessLogin to facebook {}", fault.getMessage());
  17. }
  18. }, true);
  19. }

This is the plain facebook request (gender is correct)

  1. GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
  2. new GraphRequest.GraphJSONObjectCallback() {
  3. @Override
  4. public void onCompleted(JSONObject object, GraphResponse response) {
  5. try {
  6. System.out.println();
  7. } catch (Exception e) {}}
  8. });
  9. Bundle parameters = new Bundle();
  10. parameters.putString("fields", "id, name, email,gender,birthday,location");
  11. request.setParameters(parameters);
  12. request.executeAsync();
  13. }

Any suggestions?

Thanks

Leave a Comment

Comments (12)

photo
1

Hi Kevin,

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

Regards,

Mark

photo
1

Hi Mark,

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

Best regards

photo
1

Hi Kevin,

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

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

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

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

from here:

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

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

photo
1

1. The gender field maps to the property "gender" which is a column in my user table. The result from my enum is this:

  1. facebookFieldMappings.put("gender", "gender");

2. 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

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

3. These are the fields I want to get for the user.

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

photo
1

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?

photo
1

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

photo
1

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

Regards,

Mark

photo
1

Thank you very much for the help.

Best regards,

Kevin

photo
1

For tracking purposes the internal ticket number is BKNDLSS-17218

photo
1

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

photo
1

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.

photo
1

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