1
votes

I added Facebook login button to my code. it works well.

Assuming that the user logs in via facebook and unchecks the 'user_friends' permission: 'onSuccess' function will be called so the user data can be taken from the loginResult.

Next time when he opens the app, he will get the facebook permission screen in order to allow the 'user_friends' permission. Let's say that he unchecks it again: 'onCancel' function will be called although the user will be now logged in automatically as expected (because he has never logged out).

How can I get his data now in onCancel? (because I know that he is logged in but unchecked some permission)

The User logged in last time and not this time so onSuccess won't be called this time

mCallbackManager = CallbackManager.Factory.create();
mLoginButtonFacebook.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {

    }
    @Override
    public void onCancel() {
        AccessToken token = AccessToken.getCurrentAccessToken();
        if (token != null) {            
            // here I would like to retrieve the user data
            // the user is logged in with canceled permissions
        }
    }
    @Override
    public void onError(FacebookException exception) {

    }
});
1

1 Answers

0
votes

Succeeded! sorry for your time and thanks.

AccessToken accessToken = AccessToken.getCurrentAccessToken();

GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
    @Override
    public void onCompleted(JSONObject object, GraphResponse response) {
        // object will contain the user data
    }
});