Facebook login native promise available but not working [solved]


#1

Hi , i’m facing a little issue with facebook login plugin (with a lot of another plugin too)
so i installed ionic-native and the plugin with $ ionic plugin add cordova-plugin-facebook4

and tried to run it into my app like this

  fblogin(){
    this.platform.ready().then(() => {
      Facebook.login(["email, public_profile"]).then((result) => {
        this.rootRef.$authWithOAuthToken("facebook", result.access_token).then((user) => {
          console.log(user)
        })
      })
    })
  }

when i click the button , i have error message

Native: tried calling Facebook.login, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

the plugin dont work in simulator or devices , anyone installed facebook plugin in his app?


#2

I have the same problem , I think this is because using the ionic 2 -ts , the plugin cord -plugin- facebook4 not yet there is a typescript .
Can anyone help us?


#3

tested =) works fine with babel ionic version , maybe something with typescript, all plugin works fine with babel version but typescript …


#4

exactly , also made ​​a new test, the compiler complains that there is not facebookConnectPlugin but when compiled and executed it works.


#5

tests this excemplo https://github.com/fuffenz/ionic2-native-facebook-login


#6

I think the issue is indeed that you don’t have the typing file for the plugin. However, you might want to give ionic-native a try, there seems to be a plugin for facebook: https://github.com/driftyco/ionic-native/tree/master/src/plugins


#7

I could not use the ionic -native and cordova-plugin-facebook4 , you would have some practical example to see how I use?


#8

i’m using ionic-native in my case , as you can see Facebook.login , instead of the term provided by the plugin itself


#9

Unfortunately not, I’ve never used it myself (yet) :\


#10

You might want to check out the new Ionic User offering which handles Facebook login I think.


#11

I’m trying to USE IT with typescript but without success :frowning:
I get THAT Message
ORIGINAL EXCEPTION: TypeError : this.facebook.login is not a function


#12

thanks richard , i’m using firebase and geofire , firebase facebook login works perfectly , but i was looking for a native solution. and ionic.io dont provide a solution like geofire , so i prefer to keep using firebase for the moment . i will look at ionic.io user .


#13

please paste , what you are doing


#14
import {Page, Platform} from 'ionic-angular';
import {Facebook} from 'ionic-native';

@Page({
    templateUrl: 'build/pages/login/login.html',
    providers: [Facebook]
})
export class Login {
    public platform;
    public facebook;
    constructor(platform: Platform, facebook: Facebook ) {
        this.platform = platform;
        this.facebook = facebook;
    }
     login() {
        if(this.platform.is('cordova')) {
            this.facebook.login([ 'email, publish_actions' ], (success) => {
                    console.log(JSON.stringify(success));
                },(err) => {
                    console.log(JSON.stringify(err));
                });
            
            } else {
                console.log("Please run me on a device");
            }
    }    
}

#15

try Facebook.login instead of this.facebook.login and you can delete facebook: facebook from dependency injection , and this.facebook = facebook , also public facebook


#16

Partially worked for me , now he is presenting this error in xcode console , you already have seen something?

Mar 10 13:15:53 Developers-Mac ToNaBalada[6348]: Starting login Mar 10 13:15:53 Developers-Mac ToNaBalada[6348]: *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> Permissions should each be specified in separate string values in the array.


#17

its about the facebook permissions , as it say , you should put each permissions into separate string in the array ,try to just take email for testing , i will also test


#18

Thanks for the help , I did as you said and I could make it work
Thank you.


#19

should works properly now , for me its working , the issue was on the permission , former cordova plugin for facebook was letting us to pass permission into one string , but now we need to separate them, so thank you pointing this out

cheer


#20

Hey - do you mind confirming what you did to fix this?