-1

Im using the latest Facebook sdk in my application i was able only to get the name and the id only but not the other things here is my code

enter code here
fb_login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)
        {
            onFblogin();
        }
    });
   // Private method to handle Facebook login and callback
private void onFblogin()
{
    // Set permissions
    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile","email","user_birthday","user_about_me"));

    LoginManager.getInstance().registerCallback(callbackmanager,
            new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {

                    System.out.println("Success");
                     GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                                @Override
                                public void onCompleted(JSONObject json, GraphResponse response) {
                                    if (response.getError() != null) {
                                        // handle error
                                        System.out.println("ERROR");
                                    } else {
                                        System.out.println("Success");
                                        try {
                                            String jsonresult = String.valueOf(json);
                                            System.out.println("JSON Result" + jsonresult);
                                            String id = json.getString("id");
                                            String email = json.getString("email");
                                            //String name = json.getString("name");
                                            //String dob = json.getString("birthday");
                                            //String gender = json.getString("gender");
                                            //String about = json.getString("about");
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }


                                    }
                                }

                            }).executeAsync();

                }

                @Override
                public void onCancel() {
                    Log.d("Tag on cancel","On cancel");
                }

                @Override
                public void onError(FacebookException error) {
                    Log.d("Tag on error",error.toString());
                }
            });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    callbackmanager.onActivityResult(requestCode, resultCode, data);
}

is there anything I'm missing in my code . Any help would be appreciated.

Mostafa Addam
  • 6,956
  • 4
  • 20
  • 38

2 Answers2

1

You need to request every field you want to have returned specifically.

See the answer at

Community
  • 1
  • 1
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • hey thanks i was also stuck there. but i wanna know if we can get phone number from facebook. – Aiyaz Parmar Sep 14 '15 at 13:37
  • @AiyazParmar You cannot get the phone number because it is not exposed via the Graph API, see https://developers.facebook.com/docs/graph-api/reference/user#Reading – Tobi Sep 14 '15 at 13:45
  • @AiyazParmar you cannot take the phone number through graph api, as there is no permission to access that. Even Facebook Messenger also asks for Your Phone Number first time for configuring. – Vipul Asri Sep 14 '15 at 13:48
  • @vipul_asri I think it's unnecessary to post a duplicate comment – Tobi Sep 14 '15 at 14:05
1
//Callback registration
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {

            GraphRequest request = GraphRequest.newMeRequest(
                    AccessToken.getCurrentAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            try {

                                fb_id = object.getString("id");

                                fb_gender = object.getString("gender");

                                JSONObject obj1 = object.getJSONObject("picture");
                                JSONObject obj2 = obj1.getJSONObject("data");


                                fb_name = object.getString("name");

                                JSONObject obj = object.getJSONObject("age_range");
                                fb_age = obj.getString("min");


                            } catch (JSONException e) {

                            }
                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,gender,age_range,picture");
            request.setParameters(parameters);
            request.executeAsync();

        }

        @Override
        public void onCancel() {
            // Do Nothing
        }

        @Override
        public void onError(FacebookException exception) {
            // Do Nothing
            Log.e("exception", "->" + exception);
        }
    });
Vipul Asri
  • 8,903
  • 3
  • 46
  • 71