skip to Main Content

Iam using facebook login for android app. I Am getting email and other details using Facebook API. I have following questions:

1) How to fetch email from Facebook API, when user used their mobile no. for login.

2) How we know that the user logged in with mobile number or email in Facebook login API in android?

Please Guide.

2

Answers


  1. If the user logged in with his mobile phone, you will not get an email. You can present an input field and ask the user for his email right after login.

    Login or Signup to reply.
  2. You can get the user email id which user has used in facebook by:-

    loginButton.setReadPermissions("email");
    
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code
                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.getString("email");
    
                            }
                        });
    

    You can redirect to another activity by:-

    private FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                //call your activity here
            }
    
            @Override
            public void onCancel() {
    
            }
    
            @Override
            public void onError(FacebookException e) {
                Log.d("Exception",e.getMessage());
    
            }
        };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search