Ionic 4: failed facebook login with android when the native facebook app is installed

0

I am working in an app using Ionic 4. One of the requeriments is the user can log in using facebook. I follow this tutorial: https://www.djamware.com/post/5d949fa24ca99c5ee51238ef/ionic-4-tutorial-facebook-login-example, facebook and works almost perfectly the functionality.

I am using this app: https://github.com/jeduan/cordova-plugin-facebook4

Testing the app I found out the login fails when the native android facebook app is installed in the device.

I have replicated, the experiment in three diferents devices.

Here is the process when facebook app is not installed in the device:

enter image description here

The when I do click in the facebook login button, the facebook login box appears perfectly:

enter image description here

Now, when I tried to do the same when the facebook app is installed in the device happen the following:

enter image description here

I do click in the facebook login button

enter image description here

The login box of the facebook app appears, and I logged in the the facebook app.

enter image description here

But this error is show: “There is an error in logging you into this application. Please try again later”

I uninstalled the facebook app, and the login works again.

This is my login facebook function code:

    fbLogin() {
this.platform.ready().then(() => {

      if (this.platform.is('android')) {

  this.fb.login(['public_profile', 'user_friends', 'email'])
    .then(res => {
      if (res.status === 'connected') {
        this.isLoggedIn = true;
        this.getUserDetail(res.authResponse.userID);
        this.router.navigateByUrl("/tutorial");
      } else {
        this.isLoggedIn = false;
      }
    })
    .catch(e => console.log('Error logging into Facebook', e));




    }

});

}

I found this a similar app with another facebook login plugin for react: https://github.com/facebook/react-native-fbsdk/issues/633

Their “workaround” was to force the app to call regular facebook login box like this:

if (Platform.OS === "android") {
            LoginManager.setLoginBehavior("web_only")
        }

Is any similar “workaround” or way to force to use the web facebook login box without call the facebook app?

Thank you.

I don’t know if what I did was correct, I don’t know if what I did was correct, but I wanted to put on record.

I check the plugin files. I studied one file in particular: ConnectPlugin.java

From what I see in others forums, I did the following

I added this library

import com.facebook.login.LoginBehavior;

And any line where the following command was:

LoginManager.getInstance().logInWithReadPermissions(cordova.getActivity(), permissions);

In the line before I added this:

  // Create the request
            LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY);
            LoginManager.getInstance().logInWithReadPermissions(cordova.getActivity(), permissions);

And worked perfectly. Now I can login in when the facebook added is installed.

I know this is a workaround.

Greettings.

In which file are these changes to be made? Do you get the exact solution for this?

In this file:

ConnectPlugin.java

Look for this line (appears like three times)
LoginManager.getInstance().logInWithReadPermissions(cordova.getActivity(), permissions);

before this lines I added (in all)
LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_ONLY);

This is the file path: plugins\cordova-plugin-facebook4\src\android

thanks for reply…but it’s not working for me…

Facebook login via browser works perfectly but not working when native has Facebook app installed.

is there any other solution for this?

Hello Everybody:

I can confirm is the same behavior in IOS with native Facebook App Installed, in Android works well.

This my snippet:

  facebookLogin(): Promise<any> { 
    return this.facebook.login(['email']).then(
      response => {
        const facebookCredential = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
        firebase.auth().signInWithCredential(facebookCredential)
          .then(success => {
//Expecting data here when the popup get closed, but nothing happens, instead in the app the process  starts again and again, 
            console.log("Firebase Success: " + JSON.stringify(success));
          });
      }
    ).catch((error) => {
      console.log(error)
    });
  }