Ionic2 Facebook Login Problem

I’m trying to do login via facebook using ionic-native, that uses the cordova-plugin-facebook4 plugin, that is forked from the phonegap-facebook-plugin plugin. I import it with import { Facebook } from 'ionic-native';.

The 1st. problem is that I can’t use in the browser, even calling Facebook.browserInit(APP_ID, VERSION), but as a workaround in this case I don’t use ionic-native. Instead, I load the script // directly in my .ts file and use the FB object when I’m in the browser (development). It works showing a facebook modal dialog, but would be nicer if the Facebook.login from ionic-native handled the login when the platform is the browser (it seems like browserInit is specifically for that).

The 2nd. problem is that for native apps the APP_ID is defined in the config.xml, so I can’t just switch an enviromental variable (or a variable in a file) to use a different APP_ID for development/production along with all other settings for the environment. I have to change the APP_ID manually (and remember to change) in the config.xml (or create a more complex build process to generate the config.xml dynamically, which, for the moment, I don’t consider doing). This is not a major problem, but an option to define the APP_ID in a .ts file and use it dynamically (like with browserInit) would come in hand.

The 3rd. problem is the one that must be solved. I tested with ionic run android in an AVD and could do the login :slight_smile:. But when I executed to run in my android device it showed in the facebook dialog an error about fail to start session, try again later (that is, never), or something like that :disappointed:. So I tried to understand what happened, and it occured because I had a facebook app in my device, but the AVD hadn’t. So I uninstalled my facebook and messenger apps and it worked (with the plugin login dialog, like in the AVD). After that I can log again whenever I want with my facebook account, even after installing the facebook app again. But if the users can’t log in the first time, and need to uninstall the facebook app (inviable), that would be a huge problem.

The login call is just:

Facebook.login(['email']).then(response => response.authResponse)

I see that the problem must be happening because my app is trying to use the facebook app login, but for some reason it can’t do it right. It seems that developing directly in android I can disable it using SessionLoginBehavior.SUPPRESS_SSO, like if the user hadn’t the facebook app.

The problem probably isn’t related to Ionic2 specifically, but with a cordova plugin, but considering that Facebook is in ionic-native I think this is a proper place to ask.

My question is:

1) Is there a solution to this (anyone experienced this?), so that my app can use the facebook app login (when the user has the facebook app)?

2) If not, is there a way to use SessionLoginBehavior.SUPPRESS_SSO or something similar in cordova-plugin-facebook4 (like a setting or something like that)?

Thanks in advance.

You use InAppBrowser plugin to provide login through Facebook.
For my StackCook app on Android ( please search for that in playstore if you want to test logging in via Facebook) I have Facebook login is one of the options and it worked. That’s because I am just using the browser plugin.

Thanks for your reply @jagansai , but if possible I would prefer that the user didn’t need to log in if it is already logged in the facebook app (only grant the permissions).

Found the solution! Just needed to use android as the key hash password. I was using another one because I didn’t think this was relevant. Weird that this is not said in the facebook quick start guide to use the android platform…