skip to Main Content

I want to access the user birthday & gender, but I am getting an error when I try to access the birthday.I am using the Facebook SDK version facebook-android-sdk:4.18.0.

It gives me this error:

{Response: responseCode: 400, graphObject: null, error: {HttpStatus:
400, errorCode: 100, errorType: OAuthException, errorMessage: (#100)
Tried accessing nonexisting field (user_birthday) on node type
(User)}}

Here is my code:

public class MainActivity extends AppCompatActivity {
    private CallbackManager callbackManager;
    private TextView info;
    private LoginButton loginButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();

        setContentView(R.layout.activity_main);
        info = (TextView)findViewById(R.id.info);
        loginButton = (LoginButton)findViewById(R.id.login_button);
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                GraphRequest request = GraphRequest.newMeRequest(
                        loginResult.getAccessToken(),
                        new GraphRequest.GraphJSONObjectCallback() {
                            @Override
                            public void onCompleted(JSONObject object, GraphResponse response) {
                                Log.v("LoginActivity", response.toString());

                                // Application code
                                String email = object.optString("email");
                                String birthday = object.optString("birthday");
                                String name = object.optString("name"); // 01/31/1980 format
                                info.setText("email:  " +
                                        email + "n" +
                                        "birthday " + birthday+
                                "n name"+name);
                            }
                        });
                Bundle parameters = new Bundle();
                parameters.putString("fields", "id,name,email,gender,user_birthday");
                request.setParameters(parameters);
                request.executeAsync();

            }

            @Override
            public void onCancel() {
                info.setText("Login attempt cancelled.");
            }

            @Override
            public void onError(FacebookException e) {
                info.setText("Login attempt failed.");
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
}

2

Answers


  1. In the parameters you should use birthday instead of user-birthday:

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

    See the documentation for available fields of user bio:
    https://developers.facebook.com/docs/graph-api/reference/user/

    Login or Signup to reply.
  2. Some Facebook integrations require approval before public usage.

    Without this you will received an ERROR message like this:

    Facebook error: “(#100) Tried accessing nonexisting field (user_birthday) on node type (User)”
    

    Until reviewed and approved by Facebook, your app can use only the public user’s profile and email.

    See next useful recommendations:

    Access to the date and month of birth of a person. Access to a
    person’s year of birth depends on their privacy settings and the
    access token used to request this field.

    Please note that most integrations require only the age_range field.

    Check If an application requests this permission, Facebook specialists
    should check how it will be used.

    When sending an application for review, you should specify exactly why
    the age_range permission is not enough in this case.

    Next links will be helpful for it:

    https://developers.facebook.com/docs/facebook-login/permissions#reference-user_birthday
    https://developers.facebook.com/docs/facebook-login/review/how-to-submit

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search