Wizcorp / phonegap-facebook-plugin

The official plugin for Facebook in Apache Cordova/PhoneGap
Other
1.91k stars 2.01k forks source link

First call to login is causing 4201 : User cancelled dialog #1063

Open KeKs0r opened 9 years ago

KeKs0r commented 9 years ago

I am integrating Facebook login with this plugin in my app.

But when calling the facebookConnectPlugin.login the first time always results in a 4201. "{"errorCode":"4201","errorMessage":"User cancelled dialog"}"

Although I am not cancelling, it happens automatically. Is someone else experiencing something similar?

Anjaney26 commented 9 years ago

Yes I have also same problem??

On Fri, Jul 10, 2015 at 10:17 PM, Marc Höffl notifications@github.com wrote:

I am integrating Facebook login with this plugin in my app.

But when calling the facebookConnectPlugin.login the first time always results in a 4201. "{"errorCode":"4201","errorMessage":"User cancelled dialog"}"

Although I am not cancelling, it happens automatically. Is someone else experiencing something similar?

— Reply to this email directly or view it on GitHub https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1063.

Anjaney Mishra Cont. No.:- 08285801866 email :- anjaneymishra1989@gmail.com

ismailsaglam commented 9 years ago

Yes, I have too..

silvanoAdami commented 9 years ago

Same problem to me on android... Have you found a solution or a workaround? It seems really a blocking bug... Thanks

KeKs0r commented 9 years ago

I don't have a solution. I have an ugly hack to call the dialog twice. Which is far away from a good solution.

On 29 July 2015 at 09:54, silvanoAdami notifications@github.com wrote:

Same problem to me on android... Have you found a solution or a workaround? It seems really a blocking bug... Thanks

— Reply to this email directly or view it on GitHub https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1063#issuecomment-125873851 .

silvanoAdami commented 9 years ago

Hi Marc,

thank you for your fast reply. I coded your suggestion and it worked.

Then I looked deeply in my code and found (due to framework based on jQuery) I was "attaching" twice, to my button "LOGIN with FB", the call "facebookConnectPlugin.login". After removing this doubled call the problem disappeared from root. No more "User cancelled dialog".

Hope my error could help someone else.

Silvano

On Wed, Jul 29, 2015 at 10:15 AM, Marc Höffl notifications@github.com wrote:

I don't have a solution. I have an ugly hack to call the dialog twice. Which is far away from a good solution.

On 29 July 2015 at 09:54, silvanoAdami notifications@github.com wrote:

Same problem to me on android... Have you found a solution or a workaround? It seems really a blocking bug... Thanks

— Reply to this email directly or view it on GitHub < https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1063#issuecomment-125873851

.

— Reply to this email directly or view it on GitHub https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1063#issuecomment-125877284 .

prateek-js commented 9 years ago

Keksor can you tell how u are calling the dialog twice

KeKs0r commented 9 years ago

just having a variable that counts the attempts and then when there was no attempt yet retry after the cancel. and if it is cancelled then. just accept it.

On 11 August 2015 at 16:28, Prateek Desai notifications@github.com wrote:

Keksor can you tell how u are calling the dialog twice

— Reply to this email directly or view it on GitHub https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1063#issuecomment-129905175 .

prateek-js commented 9 years ago

Tried this way also but both time getting failure callback and response as 4201 errorcode.

from app it is going to facebook and coming back to failure callback. can anyone help where i might have committed the mistake.

steps:- installed plugin with app id and app name. uploaded hash key both from code and command line to facebook

yonihei commented 9 years ago

Same problem... (didn't fix the hash though) any ideas?

kartik115 commented 9 years ago

same problem ? Fixed the hash also. Update - The test user is already logged in the app. But on getFbLoginStatus it is giving me unknown status. Do anybody know why this unknown status is appearing? I am calling Facebook Login there so possibly it is giving me error code 4201

prateek-js commented 9 years ago

try deleting the facebook app from ur mobile and then give it a try. Maybe its not taking correct app id. this was the case with me. it was taking variable $APP_ID instead of my given numeric app id

kartik115 commented 9 years ago

Yes I have tried it already @prtku1990 It is working fine without native Facebook app. But I want it to be working with native Facebook app. Any ideas ?

kartik115 commented 9 years ago

Yeah got the solution. Thanks to @prtku1990 For those who are getting this error. Goto plugin.xml file of Cordova Facebook. Change the $APP_ID and $APP_name with the App Id and App name. It worked for me.

yonihei commented 9 years ago

unfortunately, i have changed it as well, uninstalled facebook and nothing helped.

these r the lines i changed (i took off the "<" and such since it removed it from this comment): preference name="APP_ID" preference name="APP_NAME"

since it didnt work i tried to change this as well: string name="fb_app_id">$APP_ID string string name="fb_app_name">$APP_NAME string

<preference name="8*******1" />
<preference name="V*****o" />
    <string name="fb_app_id">8**********1</string>
    <string name="fb_app_name">V*****o</string>

iv tried with and without $ by te side of my app's id and app's name i'v tried changing only one of the pairs. iv tried to use cordova build android every time at the android platform.inside the facebook plugin

always getting the same error #4201 :( am i missing something obvious?

p.s. when my native facebook is not connected to my acc, it goes there, asks for password and then fails the same way (4201)

p.s2. i created a plain cordova (non ionic) new project and the plugin worked

Edit: It is working, yey! i made two main changes, im not sure if the second was really required: 0) note that using copy-paste, sometimes the char " change to a different thing, so it causes problems. 1) i used ionic plugin add.... now i used cordova as i saw that a clean cordova project worked 2) i downloaded the zip file and used -d when added the plugin: cordova -d plugin add C:\Users\y_\Desktop\fb_phonegapplug\phonegap-facebook-plugin-master --variable APP_ID="8__1" --variable APPNAME="V****o"

gilhanan commented 8 years ago

Hi buddies, i found solution for mine 4201 error

Theres bug when using angular and ionic, ngClick fires twice: https://github.com/driftyco/ionic/issues/1022

So it called login twice each click, make it call once fix.

I think appropriate would save headache :)

lightwaxx commented 8 years ago

This issue is only on someone else's phone. On my phone, it works perfectly. When I install it on someone else's phone and login into facebook, I get the error {"errorCode":"4201","errorMessage":"User cancelled dialog"}. This is such a pain

ashishsajwan commented 8 years ago

any update guys ??? @aogilvie @caabernathy @stevengill @filmaj

lightwaxx commented 8 years ago

I figured out why mine was also not working correctly. The issue is somewhere where this is fired twice. Look for it in your code. Here is my code below document.addEventListener("deviceready",onDeviceReady,false); function onDeviceReady() {

} $(function(){ //Check status on start //getStatus(); $('button.login').click(function(){ //console.log('Working click'); initApp(); //console.log(userID);

});
$('button.logout').click(function(){
    // endApp();
});

}); var fbLoginSuccess = function (userData){ //alert("UserInfo: " + JSON.stringify(userData)); // console.log('test'); // console.log(userData); // return userData.authResponse.userID; // getUser UserInfo
getUserInfo();
}

function initApp(){ facebookConnectPlugin.login(['email', 'public_profile'], fbLoginSuccess, function (error){ console.log(error); } ); } function endApp(){ facebookConnectPlugin.logout( fbLoginSuccess, function (error){ console.log(error); } ); } //Check If user is logged into facebook function getStatus(){ facebookConnectPlugin.getLoginStatus( function (status){ console.log(status); } ); }

// function getUserInfo(){ facebookConnectPlugin.api('me/?fields=id,email,name', ["public_profile"], function (result) { console.log(result); }, function (error) { console.log(error); }); }

yonihei commented 8 years ago

We have experienced issues of double-openings in facebook and cordova share plugin. (specifically on iphone 5s and on android one plus one). I suspect Crosswalk, but i did not focus this issue nor proved it.

Freundschaft commented 8 years ago

hmhm i experience this as well, surprisingly more on release build of the apk than on debug builds, can someone confirm this?

ashishsajwan commented 8 years ago

yeah same here .. happens more on release builds.. than on debug builds..

@Freundschaft

Freundschaft commented 8 years ago

it woul be really interesting to know where this issue comes from, as it is quite annoying, maybe ill dig into that in the next couple of days with adb logcat

ashishsajwan commented 8 years ago

@Freundschaft while reading this thread i noticed many people saying event trigger twice because of that this bug is coming. But i think while that may also be the reason but in my case no events are triggered twice but i still face this bug for almost 30 to 40 % of times..

chotkos commented 8 years ago

Still having it everytime in Backbone+Phonegap app

StephJan commented 8 years ago

Same here on Ionic ... randomly appears (more often than not), no solution found so far.

Freundschaft commented 8 years ago

I figured out what was causing the issue by the way. Especially for ionic users: take care that you check with facebookConnectPlugin.getLoginStatus(Function success, Function failure) before you actually log in, because if the user is already logged in, then the login will fail with a confusing error message.

Doing this fixed my issues, but I have to add that I am using not the original plugin, but the SDK version 4 version: https://github.com/jeduan/cordova-plugin-facebook4

TallisSouza commented 8 years ago

Are you guys using the ionic app_id or facebook app_id? I was using the app_id that ionic gives and was causing this problem, when I change to facebook's id, it worked.

yonihei commented 8 years ago
petervojtek commented 8 years ago

I faced this issue as well with ionic with following call:

FB.login(['public_profile', 'email', 'user_friends', 'user_birthday'])

I found out that when I change it to:

FB.login(['public_profile', 'email'])

it starts working. Well, what a woodoo programming :)

ELEME07 commented 8 years ago

I am getting the same error on ionic2, this is my code: ` Facebook.login(['public_profile','email']) .then((_response) => { console.log(_response); console.log('Entra al then'); _authInfo = _response;

    return this._FBUserProfile();

  }).then((success) => {
    console.log('Success!!');
    //let p: any = firebase.auth.FacebookAuthProvider as firebase.auth.FacebookAuthProvider_Instance
    this.fbProfile = success;
    //let creds = (firebase.auth.FacebookAuthProvider as any).credential(_authInfo.authResponse.accessToken)

  })
  .catch((_error) => {
    console.log('error en logueo');
    console.log(JSON.stringify( _error));
  })

` I still do get why, and it doesn't seem to be called twice at least in the code, i had an issue with the app_id i put the new one and it still does not work? Does anyone knows why?

HarryWiles commented 8 years ago

My solution to this problem -

I was hitting CMD+R in Safari dev tools, it would appear that the plugin's initialization persists through window refresh. My app initialized upon every refresh, each time adding an additional binding.

solution for me - don't refresh the app, close and re-open.

johnbolsberg commented 7 years ago

@ELEME07 i have the same issue, have you found solution?

johnbolsberg commented 7 years ago

@silvanoAdami how did you solve this issue?

insign commented 7 years ago

This ṕroblem was fixed here https://www.npmjs.com/package/cordova-plugin-facebook4

64jcl commented 7 years ago

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?

valsouche commented 7 years ago

@petervojtek , you just save me after few hours of search... THANKSSSSSS

cstinfotech commented 7 years ago

@petervojtek , Thanks you saved my evening.

rafaelwilsondantas commented 7 years ago

You can use the method getLoginStatus() before doing the login, because It happens when the user already loged with the app. So the getLoginStatus() can return "connected", "unkown", "disconnected"

lincolnthree commented 7 years ago

Changing the "AndroidLaunchMode" preference in config.xml solved my problems with this:

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

binarybehemoth commented 6 years ago

You can reset a user's permissions for your app here: https://web.facebook.com/settings?tab=account

Certain permissions need to be reviewed by Facebook before they become applicable, and apparently should be removed before they get approved.

emgie123 commented 5 years ago

it sounds silly... but for me it to omit the "ionic" while adding package!

cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="app_id" --variable APP_NAME="app_name" instead of: ionic cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="app_id" --variable APP_NAME="app_name"

Then also hash key was not valid(cmd output was diffrent thatn fb expected) however i just simply added the one FB told me is not listed

vicomart commented 5 years ago

In my case, I made this changes in my code

this.fb.login(['public_profile', 'user_frinds' ,'email']) to this.fb.login(['public_profile', 'email'])

and then works

prashant-dhumane commented 4 years ago

{"errorCode":"4201","errorMessage":"User cancelled dialog"} While login with Ionic5 firebase facebook login,
If user not share email address first time its login works , After logout, second time it give 4201 error. @vicomart

DennisSamul commented 4 years ago

I had the same problem "Cancelled by user" even when the user is not cancelling the login. This starts happening only when the fb login is interrupted and after that it stays.

I solved it by checking the login status when i receive the login attempt status as cancelled by user and if it is logged in. I performed fb.logout and called the login function again.

Hope this helps some one.

prashant-dhumane commented 4 years ago

hi, this.fb.getLoginStatus().then((res) => { if(res.status === 'connected') { this.fb.logout().then(() => { resolve(); }).catch(() => { reject(); }); } at logout, this call. fix issue.