Backendless Support
 
Solved

Facebook login android

i try to migrate to backendless 4.x and still can't login with facebook. the backendless user is always returned by null.

i was using the deprecated method which in 3.0 documentation so i changed to the new method which take access token as a parameter but unfortunately both of the methods return the backendless user in the callback with null and below is my code please comment if u can help...

String[] map_facebook = getResources().getStringArray(R.array.login_map_facebook_fields);

String[] map_backendless = getResources().getStringArray(R.array.login_map_backendless_fields);

if (map_facebook.length != map_backendless.length)

throw new IllegalStateException("R.array.facebook_login_permissions's length must be equal to R.array.fb_login_map_backendless_fields' length.");

final Map<String, String> facebookFieldsMappings = new HashMap<>(map_facebook.length);

final List<String> facebookPermissions = Arrays.asList(getResources().getStringArray(R.array.facebook_login_permissions));

for (int i = 0; i < map_facebook.length; i++)

facebookFieldsMappings.put(map_facebook, map_backendless);

LoginManager.getInstance().logInWithReadPermissions(this,facebookPermissions);

LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

@Override

public void onSuccess(LoginResult loginResult) {

Toast.makeText(ActivityLogin.this,loginResult.getAccessToken().getToken(),Toast.LENGTH_SHORT).show();

Backendless.UserService.loginWithFacebookSdk(loginResult.getAccessToken().getToken(),facebookFieldsMappings,new AsyncCallback<BackendlessUser>() {

@Override

public void handleResponse(BackendlessUser user) {

Log.i("BaseCustomUser", "user logged in successfully, retrieving fresh user");

Log.i("User",user.getUserId()+"");

// retrieving fresh user, since the user above is polluted with some extra attributes

Backendless.UserService.findById(user.getUserId(), new AsyncCallback<BackendlessUser>() {

@Override

public void handleResponse(BackendlessUser result) {

Backendless.UserService.setCurrentUser(result);

CustomUser customUser = new CustomUser(result);

Log.i("BaseCustomUser", "successfully retrieved fresh user: ");

redirectAfterLoggedIn(customUser);

}

@Override

public void handleFault(BackendlessFault fault) {

Log.w("BaseCustomUser", "failed to retrieve fresh user: " + fault.toString());

}

});

}

@Override

public void handleFault(BackendlessFault fault) {

Log.e("BaseCustomUser", "user failed to log in: " + fault.toString());

}

},true);

}

@Override

public void onCancel() {

}

@Override

public void onError(FacebookException error) {

}

});

Leave a Comment

Comments (2)

photo
1

Thank's the problem was solved i forget to change the new App Id