简体   繁体   中英

Facebook Graph API not returning Gender

I am using Facebook SDK to sign-in a user. To get the gender I have added user_gender permission in the permission list.

List<String> accessPermissions = Arrays.asList("user_gender", "email", "user_birthday");
LoginManager.getInstance().logInWithReadPermissions(activity, accessPermissions);

After which I get the access token. Now I am passing this access token to the backend team. And the backend team is using Facebook Graph API to get the user details like birthday, gender, email, etc.

They hit the following API to get user details.

https://graph.facebook.com/me?access_token=dummyaccesstoken&fields=name,gender,birthday,email

They are able to get details like email and birthday. But they are not able to get the gender of the user. Since it is a GET API, I can also see that we are not getting the gender of the user.

However, if we try to get the details in Android itself instead of passing the access token to the backend, then it works fine.

      GraphRequest request = GraphRequest.newMeRequest(
              loginResult.getAccessToken(),
              new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                    JSONObject object,
                    GraphResponse response) {
                  Log.d("Response", "response is "+response.getJSONObject().toString());
                  // Application code
                }
              });
          Bundle parameters = new Bundle();
          parameters.putString("fields", "id,name,link, gender");
          request.setParameters(parameters);
          request.executeAsync();

So what is the issue in the Facebook Graph API? Why is it not able to return the gender? Anyone else faced the issue?

List<String> accessPermissions = Arrays.asList("user_gender", "email", "user_birthday");
LoginManager.getInstance().logInWithReadPermissions(activity, accessPermissions);

write instead of user_gender and email and user_birthday   

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

and write the Bundle request params

 Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name,email,gender,birthday");
        request.setParameters(parameters);
        request.executeAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM