jeduan / cordova-plugin-facebook4

Use the latest Facebook SDK in your Cordova and Ionic projects
Other
765 stars 510 forks source link

Login method fail without any error message. #499

Closed milagic closed 6 years ago

milagic commented 7 years ago

Using Ionic 2 to create a login page, but I'm unable to understand where the issue is since the login API fails silently (without any error message). Env: Android.

this.fb.login(['public_profile']) .then((res: FacebookLoginResponse) => { console.log('Logged into Facebook!', res); // Store To App User Data. this.nav.setRoot(HomePage); }) .catch(e => console.error('Error logging into Facebook',e));

This results in -> Error logging into Facebook Object {}

cesarlvielma commented 7 years ago

:+1: Same issue Here.

andrewoodleyjr commented 7 years ago

+1

mrcomac commented 7 years ago

do you add Facebook provider in app.module.ts??

import { Facebook } from '@ionic-native/facebook'; ..... providers: [ ... [Facebook] ]

eusthace811 commented 7 years ago

@mokrea Can you actually show what are you importing?

mrcomac commented 7 years ago

import { Facebook } from '@ionic-native/facebook';

milagic commented 7 years ago

That's exactly what I did, but it doesn't work.

mrcomac commented 7 years ago

check this: https://github.com/mokrea/ionic2-facebook-login-example (uploaded and tested today and working.. try create a new project and change app.modules.js and home.js to test) https://github.com/danyalzia/ionic2-facebook-play (it's the source code i used, there are much more examples here)

txavier commented 7 years ago

@mokrea This worked for me thanks. I also had to go through that android facebook login set up (https://developers.facebook.com/docs/facebook-login/android). I had to set the package name, default activity class name, for which i just appended 'MainActivity' onto my package name. Then I also had to set the development key hash using keytool. Enabling single sign on on that facebook login android page was the last thing i needed before my app was able to successfully login with facebook in development.

gigeos commented 7 years ago

@txavier can you show sample code ? Do you use browserInit before login() or just login()?

txavier commented 7 years ago

Hey @gigeos , I am using Ionic 2. I added a login button to my home page and just included this code. Here you go:

`loginClick() { this.fb.login(['public_profile']) .then((res: FacebookLoginResponse) => { let userId = res.authResponse.userID; let accessToken = res.authResponse.accessToken; let expiresIn = res.authResponse.expiresIn; let session_key = res.authResponse.session_key;

    console.log('Logged into Facebook! ' + userId, res);

    this.navCtrl.setRoot(AssignedClassesPage);
  })`
gigeos commented 7 years ago

Thanks @txavier but I don't understand I do it and I have a message in Facebook popin which say: You are not logged. Please login.

Did you get it ?

aborovsky commented 7 years ago

@gigeos You mean this one? screencap

carvemerson commented 7 years ago

I get this exact problem. @aborovsky

aborovsky commented 7 years ago

@carvemerson It connected with specified Facebook OAuth app's configuration, for sure. I have 2 app on developer.facebook.com and same code (calling cordova-plugin-facebook4's login) cause to different result: success with one AppId and fail with another one.

Right now we are investigating. Suppose, cordova-plugin-facebook4 require for OAuth implicit grant flow. But why it (implicit grant) should be allowed for my Facebook OAuth app?

gigeos commented 7 years ago

@aborovsky Yes that's! I forgot what was the reason but it seems to me that was due to a configuration issue on Facebook Developper

carvemerson commented 7 years ago

Hello guys, I sove my problem only removing and adding the platform. So, I did:

ionic cordova platform rm android
ionic cordova platform add android

and now it's works for me.

Heena-Vora commented 6 years ago

@txavier as mentioned in your comment, i've already set up app in developer console. Also in app.module.ts I've made required changes.

still it throws an error without any error code or error description.

these are my plugin details : cordova-plugin-device 1.1.4 "Device" cordova-plugin-facebook4 1.9.1 "Facebook Connect" cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview" cordova-plugin-splashscreen 4.0.3 "Splashscreen" cordova-plugin-whitelist 1.3.1 "Whitelist" ionic-plugin-keyboard 2.2.1 "Keyboard"

this is my home.ts code

fbLogin() { alert("login facebook"); this.facebook.login(['email', 'public_profile']).then((res: FacebookLoginResponse) => { this.access = JSON.stringify(res); alert("success facebook"); this.facebook.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', []).then(profile => { alert("data facebook"); this.response = JSON.stringify(profile); }); }, error=> { alert("error facebook");// returns only {} this.error = JSON.stringify(error); }); // this.facebook.logEvent(this.fb.EVENTS.EVENT_NAME_ADDED_TO_CART); }

It's not working.

jaybeecave commented 6 years ago

<meta http-equiv="Content-Security-Policy" content="default-src * gap://ready; style-src 'self' 'unsafe-inline'; img-src 'self' data:; script-src * 'unsafe-inline' 'unsafe-eval'">

peterpeterparker commented 6 years ago

This question is one year old almost, I close it for inactivity. Furthermore I could confirm I don't face this problem with my app in production.

For support questions plz use other channels like Stackoverflow or Ionic forum

maikonigor commented 6 years ago

@aborovsky and @gigeos You should "add platform" on your facebook console and insert the Google Play package name, if you're trying to deploy your application in a android device.

The package name is the "widgetd id attribute" in second line of your config.xml file. like this:

in the example above, the package name is "io.ionic.starter". I strongly reccomend you to change this name to your own package name. If you search this package name in google play store will see a lot of apps that don't change it :p I Hope it can help you.
odedaramilan commented 5 years ago

You need to add an Android platform from your facebook app basic settings page and setup. Just simply follow the steps from here to create release key hashes: https://developers.facebook.com/docs/facebook-login/android

It solved the same problem for me