Facebook Login Error "User cancelled Dialog" - 4201


#1

Hi, I’m getting an error when trying to log in to Facebook. With the same problem many people have encountered and tried everything I can see. But I did not succeed.

error :
{errorCode: “4201”, errorMessage: “User cancelled dialog”}

code :
this.fb.login([‘public_profile’, ‘user_friends’, ‘email’])
.then((res: FacebookLoginResponse) => console.log(‘Logged into Facebook!’, res))
.catch(e => console.log(‘Error logging into Facebook’, e));


#3

I had the same problem in my project as well. In my case it was because the user was already logged into Facebook via my app. I solved it by always making sure to logout of Facebook on logout

this.facebook.logout().then(() => { }).catch(() => { });

You can also check to see if the user is already logged in before attempting the login again:

this.facebook.getLoginStatus().then((res) => {
    if (res.status === 'connected') {
        // Already logged in to FB so pass credentials to provider (in my case firebase)
        let provider = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
        firebase.auth().signInWithCredential(provider).then((authToken) => {
           this.authToken = authToken;
        });
    } else {
        // Not already logged in to FB so sign in
        this.facebook.login([]).then((userData) => {
            // FB Log in success
        }).catch((error) => {
            // FB Log in error
        });
    }
};

#4

Thank you very much, look for the solution and this resolved!


#5

how to resolved

i have same error.