WISHY
WISHY

Reputation: 11999

Unable to get FB user birthday, android?

I am trying to get some profile information of facebook user like name, email, birthday and location. I am not able to get the user's birthday.

callbackManager = CallbackManager.Factory.create();
    loginManager=LoginManager.getInstance();
    loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            accessToken = AccessToken.getCurrentAccessToken();
            getProfileInformationFacebook(accessToken);
            Log.e("login res", loginResult.toString());
        }

        @Override
        public void onCancel() {
            // App code
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
        }
    });

Read permissions:

loginManager.logInWithReadPermissions(this,
                Arrays.asList("user_about_me", "user_birthday", "user_location", "email"));

Graph API request:

public void getProfileInformationFacebook(AccessToken accToken) {
    GraphRequest request = GraphRequest.newMeRequest(
            accToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                        JSONObject object,
                        GraphResponse response) {
                    Log.e("object", object.toString());
                    String fbId = null;
                    String fbBirthday = null;
                    String fbLocation = null;
                    String fbEmail = null;
                    String fbName = null;

                    try {
                        fbId = object.getString("id");
                        fbEmail = object.getString("email");
                        fbName = object.getString("name");
                        fbBirthday = object.getString("birthday");
                        JSONObject jsonObject = object.getJSONObject("location");
                        fbLocation = jsonObject.getString("name");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    } 
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email,location,birthday");
    request.setParameters(parameters);
    request.executeAsync();

Graph API response:

{"id":"10153618779823958","email":"[email protected]","name":"Wishy Gupta"}

Is here something missing?

Upvotes: 3

Views: 10325

Answers (1)

kgandroid
kgandroid

Reputation: 5595

Facebook don't give user birthday by default.You have to use extended permission and submit your app for review to facebook to access user`s birthday.

See here:

https://developers.facebook.com/docs/facebook-login/permissions/v2.4

Upvotes: 7

Related Questions