Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

User cancelled dialog error everytime #125

Closed
zaggaz opened this issue Feb 4, 2016 · 42 comments
Closed

User cancelled dialog error everytime #125

zaggaz opened this issue Feb 4, 2016 · 42 comments

Comments

@zaggaz
Copy link

zaggaz commented Feb 4, 2016

Whenever I use a lollipop or higher device, login always returns 4201 User cancelled dialog.

I've checked my hashes and they seem fine as it works with Wizcorp/phonegap-facebook-plugin. However the Wizcorp/phonegap-facebook-plugin doesn't work with the official push plugin due to build issues.

Any help on this would be great! The android version i'm using is 5.1.1.

@jeduan
Copy link
Owner

jeduan commented Feb 4, 2016

Please post the dialog you're using.

@zaggaz
Copy link
Author

zaggaz commented Feb 4, 2016

_fbLogin(birthdayStr) {
    facebookConnectPlugin.login(
      ['email', 'public_profile', 'user_birthday'],
      (response) => {
        facebookConnectPlugin.api(
          '/me?fields=id,birthday,gender,first_name,age_range,last_name,name,picture.width(400),email',
          [],
          x => this._handleSuccessfulFbResponse(x, birthdayStr),
          x => this.setState({status: 'login failed'}),
        );
    }, (response) => {
        console.log(response);
    });
  }

I'm using whichever version npm gives me, the plugin.xml shows this:

lollipop 5.1.1 - oneplus two is the device that's getting this problem

@zaggaz
Copy link
Author

zaggaz commented Feb 5, 2016

Ok, I've found a solution to this. It seems that I need to delete the app and install it again in order for the facebook login to work. I have no idea why, but running straight away doesn't seem to work. I presume it's something to do with the hash keys. Thanks though, I'll update if I find out more!

@dbroadhurst
Copy link

I'm seeing the same issue even with a fresh test app.

cordova create, cordova add platform android etc

See login screen and looks like I successfully login but I get an error response

error Object {errorCode: "4201", errorMessage: "User cancelled dialog"}

@dayaki
Copy link

dayaki commented Feb 24, 2016

am having this same error: error Object {errorCode: "4201", errorMessage: "User cancelled dialog"}

anyone been able to fix it?

@gauravsaini03-zz
Copy link

Any updates on this ?

@dayaki
Copy link

dayaki commented May 14, 2016

Upgrading to the lastest version fixed this for me

@jorgemejia
Copy link

I had the same problem, my solution was on the login method, I made the request for all the permissions I want to use in that method.

@Findiglay
Copy link

Findiglay commented May 27, 2016

Experiencing the same issue currently on a Samsung s3 with 4.4.4. Working fine on my S6 with Android M though. Wondering if this is specific to older versions of Android?

@jorgemejia could you elaborate at all on what your solution was?

Updating to the latest version did not resolve it.

@marfire
Copy link

marfire commented Jul 28, 2016

It seems clear from this issue (and the parallel one in the original repository) that this is kind of a catch-all error for a variety of problems.

Just to add my experience: I got this error as a result of sending a bad app id. Correcting that fixed the problem.

As a debugging note, be sure to check the Android log (via DDMS, or whatever). That's where I was able to see the detailed exception that indicated the specific problem.

@souly1
Copy link

souly1 commented Aug 27, 2016

Just so it will be mentioned here as well, my issue was with the "singleInstance" being set for android.
Mentioned in original wizcorp plugin issues:
Wizcorp#915

@arijan108
Copy link

arijan108 commented Aug 28, 2016

For the past couple of days I had trouble getting anything to work at all (I am working in Construct 2, using Cranberrygames Phonegapp), and in XDK the jeduan facebook4 plugin. After solving everything from multidex errors and hash-keys, the final problem I was facing was this exact issue. After a couple of days of non-stop overthinking, I finally (partially) solved my problem with this one.

I can't guarantee it will work for you, however, it's worth the try. What I did is to lower the version of the plugin, and I wanted to test each, but turns out the version 1.3.0 worked just fine for me, so I stuck with that. You may or may not solve your problem with this, but another thing I did (that may or may not have helped getting the thing to work) is that I have assigned the "login" AND the "get permission" request together after clicking the button you assign.

Edit: Forgot to mention that for some odd reason, logging in works successfully and then from time to time, I still get the "user cancelled dialog" error. Quiting and starting the app works sometimes, but still annoying.

@johnbolsberg
Copy link

i have the same error

Object {errorCode: "4201", errorMessage: "User cancelled dialog"}

that's my facebooklogin function in ionic 2
` facebookLogin(){
Facebook.login(['email']).then( (response) => {
let facebookCredential = firebase.auth.FacebookAuthProvider
.credential(response.authResponse.accessToken);

  firebase.auth().signInWithCredential(facebookCredential)
      .then((success) => {
        console.log("Firebase success: " + JSON.stringify(success));
        this.userProfile = success;
      })
      .catch((error) => {
        console.log("Firebase failure: " + JSON.stringify(error));
      });

}).catch((error) => { console.log(error) });

}

who can help?`

@Rondeus
Copy link

Rondeus commented Nov 10, 2016

I was facing the same issue and the problem was with a wrong field name on the Graph API method.

In this case we were passing "?fields=email,name,user_birthday,picture.width(200).height(200)" where user_birthday is not valid. Graph API returns an error and the the plugin returns it as 4201.

You may check this as well.

@64jcl
Copy link

64jcl commented Feb 7, 2017

(Repost my comment from another thread here as its related)

Ok, we came across this issue as well once just now and it is very likely related to a change in user permissions / scope that was initially accepted by the user on the first login. If you then go and change the permissions and try to log in again, Ionic2 will for a brief moment try to login and show a facebook page which is immediately dismissed and returns the response errorCode: 4201 - errorMessage: User cancelled dialog.

I would assume that if there is a mismatch of permissions a user would have to accept a different set of permissions somehow? Perhaps this is missing in the cordova plugin? At present it seems the only way to adjust the permissions is to register a new application in Facebook and change the app to use a different APP_ID.

Perhaps anyone can help out with this?

@v3ss0n
Copy link

v3ss0n commented Feb 9, 2017

happening after lastest update , it was all fine before.

@walfridosp
Copy link

walfridosp commented Feb 15, 2017

Go to you application info, then clear data and cache, that did the trick for me.

@v3ss0n
Copy link

v3ss0n commented Feb 16, 2017

@walfridosp we did that , it won't help . tried clearing all the info , including resetting facebook data. Nothing happens

@dpaksoni
Copy link

+1, same error here. Any update?

@walfridosp
Copy link

@v3ss0n
Yes, actually it works only the first time after clearing data and cache, after that it shows the dialog again.

@dpaksoni
Copy link

Tried creating a new cordova project and then added plugin in that. It worked. But not in already existing project. Could not detect the issue.

@v3ss0n
Copy link

v3ss0n commented Mar 6, 2017

hi , the problem is with android 4.4.4
latest version cannot be logged in on android 4.4.4

please help it is important to support android 4.4.4

@jeduan please can you look into it..

@v3ss0n
Copy link

v3ss0n commented Mar 6, 2017

android < 4.4.4 dosen't work.

@oleksiy-nesterov
Copy link

oleksiy-nesterov commented Apr 3, 2017

in this case just call facebookConnectPlugin.getLoginStatus to prevent the situation, something like:

var getLoginStatus = function(){
    window.facebookConnectPlugin.getLoginStatus(
        function(data){
            if(data.authResponse){
                self.oauthDataFB = {
                    expires      : data.authResponse.expiresIn,
                    access_token : data.authResponse.accessToken
                };
            }else{
                self.oauthDataFB = null;
                getLoginError({errorCode:4201});
            }
        },
        function(e){
            getLoginError(e);
        }
    );
};

window.facebookConnectPlugin.login(
    permissions,
    function(){
        getLoginStatus();
    },
    function(e){
        if(e.errorCode == 4201 && $agent.osLowerCase === 'android'){ // <--- the solution
            getLoginStatus();
        }else{
            getLoginError(e);
        }
    }
);

@gattex
Copy link

gattex commented May 19, 2017

Any news for this issue ? It's not working for android <= 4.4. Any pr??

@v3ss0n
Copy link

v3ss0n commented May 20, 2017

interesting @oleksiy-nesterov going to give a try.

@gattex
Copy link

gattex commented May 21, 2017

It's working for me now!. I founded that this plugin is incompatible with cordova-plugin-background-mode for android version <= 4.4.
Thanks for all.

@adesst
Copy link

adesst commented Jun 5, 2017

in your config.xml add this

<preference name="AndroidLaunchMode" value="singleTop" />

i found that after adding the pref, the background-mode and facebook4
working fine in my Xiaomi2 android 4.4.4

@lincolnthree
Copy link

Changing the "AndroidLaunchMode" preference in config.xml did indeed solve my problems with this (thanks @adesst):

-  <preference name="AndroidLaunchMode" value="singleInstance"/>
+  <preference name="AndroidLaunchMode" value="singleTop"/>

This can have a few side-effects, so read up before you switch, and decide if it's for you. E.g. Your app will potentially have multiple instances open at once, which is sometimes not a great thing.

https://developer.android.com/guide/topics/manifest/activity-element.html#lmode

@jwiesmann
Copy link

Today i had the same problem (using ionic2 / fb-plugin). It looks like the demo / example on the ionic page is not correct and that causes the issue. Indeed, the error could be a bit more specific, but what i think it causes it, is the following: (thx to @Rondeus)

Example from the Ionic page:
this.fb.login(['public_profile', 'user_friends', 'email'])

If you check the Graph API from Facebook
screen shot 2017-09-03 at 22 46 27

You will see, that there is no such thing like
public_profile
after i changed it according to the fb-api
this.fb.login(['user_about_me', 'email', 'user_birthday'])
It works like expected. Hope it helps someone!

@Kavenon
Copy link

Kavenon commented Jan 4, 2018

For me it was caused by not adding user as tester of facebook application. It was hard to find, because it sometimes failed with "User cancelled dialog" message and sometimes without any message.

@rolinger
Copy link

I am getting this error too. It looks like I am able to login successfully...but I get the error when trying to do a post. Just before the post I am checking login status with 👍

      facebookConnectPlugin.getLoginStatus(
        function(response) {
          console.log("LoginStatus") ;
          console.log(response) ;
        }
      ) ;
      
      facebookConnectPlugin.showDialog(
        fbObj, 
        function (response) {  // success
          console.log("success") ;
          console.log(response) ;
          },
        function (error) { // failure 
          console.log("error") ;
          console.log(error) ;
          } 
      ) ;

Login status responds with "connected" and all the tokens, expire, session data....so my issue must be related to actually trying to post something.

Any ideas?

@rolinger
Copy link

@zaggaz - I tried what you did...deleted my app and reinstalled but that didn't change my situation. I am still getting that error when trying to post things to users FB page. My login/auth appears to work.

@jwiesmann
Copy link

Did you see this here?

A User access token with the user_posts permission.
(Check https://developers.facebook.com/docs/graph-api/reference/v2.11/post for more info)

Meaning at your login you will need to add that permission like so:
this.fb.login(['user_about_me', 'email', 'user_birthday', 'user_posts'])

Greetings...

@rolinger
Copy link

rolinger commented Jan 23, 2018

@jwiesmann - thanks for the input. I added user_posts to my login function and it did not change the outcome. I still continue to get the 4201 error:

LoginStatus: (at login)
   {status: "connected", authResponse: {…}}authResponse: {accessToken: "EAAMGv5AERbUBAImkwZC4gE8x8BTnwEvGxRw2M2TWrfnzOVZC5…", expiresIn: "5115705", session_key: true, sig: "...", userID: "10154000....."}status: "connected"__proto__: Object

Then in my app I try to post something to the user's FB page and following FB page pops up on the phone (appears to be web page) saying:

Sorry, something went wrong.
We are working on it and we'll get it fixed as soon as we can

And then when I close that page, my app gets the following error:

ErrorStatus: (at posting msg to users fb page):
   {errorCode: "4201", errorMessage: "User cancelled dialog"}

It also occurs to me the DOCS link you sent me is for the Graph API. I am trying to use the showDialog - I am wondering if that is a part of the problem. Everything I read about showDialog though indicates I should be able to post messages to a users FB page.

@rolinger
Copy link

I finally got it figured out. It was a combo of my hash key being wrong and passing the wrong parameters to the method:feed

@lincolnberryiii
Copy link

Just an FYI: You will get this error if you are trying to log the user in with the publish_actions permission, which Facebook has deprecated as of Graph API v3:

https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#login-4-24

@wkaskie
Copy link

wkaskie commented Mar 20, 2020

I have a fresh Ionic App, no customizations except the facebook4 plugin. It doesn't work. I get the same response, "user cancelled" as the error from the then/catch. I'm also using the sample code from the readme.

Error in X-Code is:

-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)

Basic setup:

    "@angular/common": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ionic-native/core": "^5.22.0",
    "@ionic-native/facebook": "^5.22.0",
    "@ionic-native/splash-screen": "^5.22.0",
    "@ionic-native/status-bar": "^5.22.0",
    "@ionic/angular": "^5.0.0",
    "cordova": "^9.0.0",
    "cordova-android": "^8.1.0",
    "cordova-ios": "^5.1.1",
    "cordova-plugin-facebook4": "^6.2.0",
    ...
}```

@adesst
Copy link

adesst commented Mar 21, 2020

I have a fresh Ionic App, no customizations except the facebook4 plugin. It doesn't work. I get the same response, "user cancelled" as the error from the then/catch. I'm also using the sample code from the readme.

Error in X-Code is:

-canOpenURL: failed for URL: "fbauth2:/" - error: "The operation couldn’t be completed. (OSStatus error -10814.)

Basic setup:

    "@angular/common": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@ionic-native/core": "^5.22.0",
    "@ionic-native/facebook": "^5.22.0",
    "@ionic-native/splash-screen": "^5.22.0",
    "@ionic-native/status-bar": "^5.22.0",
    "@ionic/angular": "^5.0.0",
    "cordova": "^9.0.0",
    "cordova-android": "^8.1.0",
    "cordova-ios": "^5.1.1",
    "cordova-plugin-facebook4": "^6.2.0",
    ...
}```

You could check your AndroidManifest.xml
if android:launchMode is set to "singleTop"

<application ... >
<activity
android:launchMode="singleTop"
...

if not set, then please check your config.xml

Another approach you could try is:

  1. Manually set AndroidManifest.xml like given example
  2. from platforms/android dir you do
    $ ./gradlew assembleDebug
  3. Run the compiled in a device
  4. Let us know if it works

tq

@wkaskie
Copy link

wkaskie commented Mar 21, 2020

Hi Team! I was able to get this working by "starting over". apparently, something was off in my environment. so I

  1. Followed some instructions for completely wiping node and nvm from the system.
  2. Did a fresh nvm installation
  3. nvm install 12 (to get node back)
  4. npm i on the project
  5. remove facebook4
  6. remove ios
  7. Finally, did a fresh install of the plugin and ios. Working as expected now....for ios, at lease

@nikky778
Copy link

nikky778 commented Jun 23, 2020

For signup process login with Facebook is working. But after login i need some more permissions from user. i.e "manage_pages" permission in order to get user's Instagram business account info which i need to get on a different page(Not on the signup page).In order to get Instagram basic info we need to login again with Fb in order to get required permissions. But every time i get the same error " 4201 : user cancelled dialog ". Code is working fine on ios , issue is with android only
I am using the code below(On a different page where i need permissions and Instagram business account linking):

    return this.fb.login(['manage_pages']).then((res) => {
   
        return this.fb.login(['email', 'public_profile', 'instagram_basic', 'pages_show_list', 
        'instagram_manage_insights']).then((res) => {

        }).catch((err) => {
         this.presentToast("Something went wrong !");
        });

  }).catch((err) => {
     alert(JSON.stringify(err));
    this.presentToast("Something went wrong !");
  });

@noahcooper
Copy link
Collaborator

This plugin is deprecated. Check out the actively maintained fork cordova-plugin-facebook-connect at https://www.npmjs.com/package/cordova-plugin-facebook-connect. If you're still experiencing issues, feel free to log an issue with more details there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests