JTM JTM - 1 year ago 109
Android Question

Why can't I get a user's first name from a GraphRequest?

I want users to be able to register for my Android app using the Facebook

. To get their information, I am performing a
with the permissions "
" and "
." According to this page, the user's first and last name should be accessible in the "
" and "
" fields. However, when I click the button, I get an error saying that there is no value for first_name. The
array that is returned is along the lines of:

{"name":"First M. Last","id":"1234567890123456"}

I have not submitted my app for review, because it is not yet complete. Could this have something to do with this problem?

Answer Source

As per official documents your login for accessing public_profile permission should look like :

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

To get Profile Info :

 private void getFbDetails(final AccessToken accessToken) {
        GraphRequest request = GraphRequest.newMeRequest(accessToken,
                new GraphRequest.GraphJSONObjectCallback() {
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {

                     //   Toast.makeText(Login.this, object.toString(), Toast.LENGTH_LONG).show();
                        Log.v("FB Details", object.toString());
                        if (object != null) {
                            name_fb = object.optString("name");
                            email_fb = object.optString("email");
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name,first_name, last_name, email,link");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download