# Facebook Login Error "User cancelled Dialog" - 4201

**URL:** <https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022>\
**Category:** Ionic Native\
**Created:** [August 6, 2017, 11:07am UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022 "2017-08-06T11:07:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcan](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mcan](https://forum.ionicframework.com/u/mcan)\
**Post date:** [August 6, 2017, 11:07am UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/1 "2017-08-06T11:07:35Z")

</div>

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));

---

<div class="post-metadata">

**Author:** ![plmetz](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/plmetz/32/106847_2.png) [@plmetz](https://forum.ionicframework.com/u/plmetz)\
**Post date:** [August 6, 2017, 3:58pm UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/3 "2017-08-06T15:58:11Z")

</div>

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:

```auto
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
        });
    }
};

```

---

<div class="post-metadata">

**Author:** ![sioessi](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sioessi](https://forum.ionicframework.com/u/sioessi)\
**Post date:** [March 19, 2018, 2:14am UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/4 "2018-03-19T02:14:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![watermelon91](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/watermelon91/32/119008_2.png) [@watermelon91](https://forum.ionicframework.com/u/watermelon91)\
**Post date:** [July 3, 2018, 9:24am UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/5 "2018-07-03T09:24:36Z")

</div>

how to resolved

i have same error.

---

<div class="post-metadata">

**Author:** ![clautm](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@clautm](https://forum.ionicframework.com/u/clautm)\
**Post date:** [April 3, 2019, 5:37pm UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/6 "2019-04-03T17:37:09Z")

</div>

I had the same error and it was because when I added the facebook native plugin I added it like:

```auto
ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"

```

Changed the values in the config.xml but it didn’t took effect. I had to remove and add it again with the correct APP\_ID (that was wrong, found the problem after uninstalling the facebook and the web popup told me the APP\_ID was unusual. After this it worked 🥳

In case you seek the remove command:

```auto
ionic cordova plugin remove cordova-plugin-facebook4 

```

---

<div class="post-metadata">

**Author:** ![santiago\_vasquez06](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/santiago_vasquez06/32/112047_2.png) [@santiago\_vasquez06](https://forum.ionicframework.com/u/santiago_vasquez06)\
**Post date:** [August 11, 2021, 11:16pm UTC](https://forum.ionicframework.com/t/facebook-login-error-user-cancelled-dialog-4201/101022/7 "2021-08-11T23:16:50Z")

</div>

This work for me! thanks
