---
title: "Android Facebook Login API returns only name and id"  
description: "Android Facebook Login API returns only name and id"  
author: "Arti Mishra"  
published: 2018-09-17  
updated: 2023-07-02  
canonical: https://www.mindstick.com/forum/34671/android-facebook-login-api-returns-only-name-and-id  
category: "android apps"  
tags: ["android", "facebook api"]  
reading_time: 5 minutes  

---

# Android Facebook Login API returns only name and id

Before [Facebook](https://www.mindstick.com/articles/44467/successful-companies-that-utilize-facebook-as-a-social-media-platform) [Login](https://www.mindstick.com/articles/12852/styles-login-form-in-android) in an [android app](https://www.mindstick.com/articles/208957/a-complete-guide-for-android-app-development), I’m Submit the [request](https://www.mindstick.com/blog/255/post-get-and-request-function-in-php) and GraphResponce Object return only ........\

```
GraphResponce : { Response: responseCode: 200, graphObject: {"name":"Development Mindstick","id":"219688002317931"}, error: null}
JSONObject: {"name":"Development Mindstick","id":"219688002317931"}
```

\
**My [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) :**

```
loginButton = (LoginButton) findViewById(R.id.fb_login_button);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
callbackManager = CallbackManager.Factory.create(); // create instance of callback manager class
if (Utils.isNetworkAvailable(getApplicationContext())) {
   loginButton.setReadPermissions(Arrays.asList(EMAIL, PUBLIC_PROFILE));
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
          accessTokenFacebook = loginResult.getAccessToken();
            final GraphRequest request = GraphRequest.newMeRequest(accessTokenFacebook, new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    Log.i("GraphResponse", response.toString());
                    Log.i("JSONObject", object.toString());
                    // Get facebook data from login
                    String email="";
                    try {
                       String userName = object.getString("name");
                       String id = object.getString("id");
                       email=object.getString("email");  // Error Generate
                        String firstName = " ", lastName = " ";
                        if (userName != null) {                            int end = userName.lastIndexOf(' ');
                            if (end >= 0) {
                                firstName = userName.substring(0, end);
                                lastName = userName.substring(end + 1, userName.length());
                            }
                        }
                        Toast.makeText(getApplicationContext(),"Facebook Login Successful",Toast.LENGTH_SHORT).show();
                        if(email.equals("")) {
                         Toast.makeText(getApplicationContext(),getResources().getString(R.string.email_permission),Toast.LENGTH_SHORT).show();
                        }
                        else {
                            loginApi("facebook", id, firstName, lastName, email);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
            request.executeAsync();
        }
        @Override
        public void onCancel() {
            Log.d("facebook Login","On cancel");
        }
        @Override
        public void onError(FacebookException error) {
            Log.v("Error", error.toString());
        }
    });
} else {
    Toast.makeText(this, getResources().getString(R.string.no_internet), Toast.LENGTH_SHORT).show();
}
```

\
**Gradle** [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) 'com.facebook.android:facebook-login:[4,5)' **\****But my need is GraphResponse object also return [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) [email](https://www.mindstick.com/articles/12870/10-easy-ways-to-manage-your-business-email-inbox) which is not easily possible in my code.**\

## Replies

### Reply by Aryan Kumar

Yes, the Facebook Login API returns only the user's name and ID by default. To get more information about the user, such as their email address or profile picture, you need to specify the `fields` parameter in the login request. For example, the following code will get the user's name, ID, email address, and profile picture:

public void loginWithFacebook() { LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "public_profile"));

Code snippet

```plaintext
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        // Get the user's profile information
        GraphRequest request = GraphRequest.newMeRequest(
            loginResult.getAccessToken(),
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject object, GraphResponse response) {
                    // Handle the response
                }
            }
        );
        request.executeAsync();
    }

    @Override
    public void onCancel() {
        // Handle the cancellation
    }

    @Override
    public void onError(FacebookException error) {
        // Handle the error
    }
});
```

}

The `fields` parameter can be a comma-separated list of any of the following fields:

- **id:** The user's ID.
- **name:** The user's name.
- **email:** The user's email address.
- **picture:** The URL of the user's profile picture.
- **cover:** The URL of the user's cover photo.
- **gender:** The user's gender.
- **locale:** The user's locale.
- **updated_time:** The time the user's profile was last updated.

You can also use the `fields` parameter to get information about the user's friends, groups, and other data. For more information, see the Facebook Graph API documentation: https://developers.facebook.com/docs/graph-api/reference/user.

### Reply by Arti Mishra

After long study, we find the solution of my problem.

First of all, I allow the Facebook permission for our [Android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) app and after that, we add the following code.

```
loginButton = (LoginButton) findViewById(R.id.fb_login_button);

FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this);
callbackManager = CallbackManager.Factory.create();  loginButton.setReadPermissions(Arrays.asList("email","public_profile"));GraphRequest request = GraphRequest.newMeRequest( accessToken,
        new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted( JSONObject object,
 GraphResponse response) {                   ………………….
              String email=object.getString("email");               ………………. // Application code
            }
        });
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");  // You can add any field as per requirement
request.setParameters(parameters);
request.executeAsync(); 
```

\


---

Original Source: https://www.mindstick.com/forum/34671/android-facebook-login-api-returns-only-name-and-id

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
