Android Facebook SDK - username is getting null

450 Views Asked by At

I am using simple facebbok to integrate facebook to my application.i need to send the facebook username to server.but i got the username as null from profile listner. here is my code

   public void loginToFacebook(View v){
    mSimpleFacebook.login(this);
}
OnLoginListener listner = new OnLoginListener() {
    @Override
    public void onLogin() {
        mSimpleFacebook.getProfile(onProfileListener);
    }
};
OnProfileListener onProfileListener = new OnProfileListener() {         
    @Override
    public void onComplete(Profile profile) {
        System.out.println(profile.getUsername());//getting null here
    }
};

I have also tried with the code,

OnLoginListener listner = new OnLoginListener() {
    @Override
    public void onLogin() {
    Profile.Properties properties = new Profile.Properties.Builder()
    .add(Properties.USER_NAME)
    .add(Properties.ID)
    .build();
    mSimpleFacebook.getProfile(properties, onProfileListener);
    }
};

But the listner is not getting fired in this case.

This is the permission i have given in the Application class

private void configureFacebook() {
       Permission[] permissions = new Permission[] {
                Permission.USER_ABOUT_ME,
                Permission.PUBLIC_PROFILE,
                Permission.READ_STREAM,
                Permission.EMAIL,
                Permission.PUBLISH_ACTION
            };
       SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
        .setAppId(Constants.FB_APPID)
        .setNamespace("namespace")
        .setPermissions(permissions)
        .build();
       SimpleFacebook.setConfiguration(configuration);
}
1

There are 1 best solutions below

11
On BEST ANSWER

You can't get username in API v2.0