Skip to content Skip to sidebar Skip to footer

Android Facebook Login With Phone Number Returns Null Username

I'm using the Facebook login code, it works well when trying to login with email. I'm now trying to login by account with phone number. private FacebookCallback

Solution 1:

It is because of the code execution style: Java execute code line by line:

so in your code:

try {
            user = new User();
            user.facebookID = object.getString("id").toString();
            user.email = object.getString("email").toString();
            user.name = object.getString("name").toString();
            user.gender = object.getString("gender").toString();
            PrefUtils.setCurrentUser(user,LoginActivity.this);

        }catch (Exception e){
            e.printStackTrace();
        }

it stops excecution in this line: user.email = object.getString("email").toString(); because of JsonException. so the below code is not executed.

to resolve null error for name pull the code of your name, others ahead. use:

try {
            user = new User();
            user.facebookID = object.getString("id").toString();
            user.name = object.getString("name").toString();
            user.gender = object.getString("gender").toString();
            user.email = object.getString("email").toString();
            PrefUtils.setCurrentUser(user,LoginActivity.this);

        }catch (Exception e){
            e.printStackTrace();
            PrefUtils.setCurrentUser(user,LoginActivity.this);
        }

Second Option

Even better to use has() method of your JSonObject like object.has("email"); so that you can parse the data more accurately according to your need.

Post a Comment for "Android Facebook Login With Phone Number Returns Null Username"