firebasefacebook-loginionic4facebook-authentication

Why 'The method FB.login can no longer be called from http pages.' does appear in my Ionic4 app?


I'm trying to setup the facebook login in my Ionic 4 application but it does not work when I use the cordova method. The console displays two errors :

The method FB.login can no longer be called from http pages.

FB.login() called before FB.init().

The web method is fully working.

facebookCordova() {
    this.fb.login(['email']).then(
      (response) => {
        const facebookCredential = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
        firebase.auth().signInWithCredential(facebookCredential)
        .then((success) => {
            console.log('Info Facebook: ' + JSON.stringify(success));
        }).catch((error) => {
            console.log('Erreur: ' + JSON.stringify(error));
        });
      }).catch((error) => { console.log(error); });
  }

The output expected is the user informations get in "success". Thanks for your help


Solution

  • The message "The method FB.login can no longer be called from http pages." still showing in console for me, but the message "FB.login() called before FB.init()" disappeared and the login functionality started to work after I did the following:

    1 - Removed the platform

    ionic cordova platform rm browser

    2 - Removed Facebook plugin

    ionic cordova plugin rm cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="MySweetApp"

    3 - Added Facebook plugin with --save (I think the --save parameter is the solution, and it is not mentioned in the documentation https://ionicframework.com/docs/native/facebook )

    ionic cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="MySweetApp" --save

    4 - Added the platform again

    ionic cordova platform add browser