Ionic/cloud-angular FacebookAuth gives empty error

2019-06-21 08:56发布

问题:

I've added ionic cloud services to my app and want to use the native FaceBook authentication.

import { FacebookAuth } from '@ionic/cloud-angular';

this.facebookAuth.login()

When running this function on an Android phone, as expected I get the Facebook prompt to ask if my app can get permissions to read profile and email. When I click YES, the function returns an empty ERROR object:

Object {}

I'm sure I am catching it right, because when I choose CANCEL on the FB prompt, I get this error object:

Object {errorCode: "4201", errorMessage: "User cancelled dialog"}

Note: I'm using remote web inspector in chrome to see the full console. Unfortunately, as this requires a real device I can not Plunker this. However, I hope someone has an idea why this could happen. I have followed all these steps, including the FB developer settings, the hash and the ionic.io settings.

回答1:

I have done that and it's working fine on the real device.If you have any question, please comment below.

Play with Git Repo

app.module.ts

import { CloudSettings, CloudModule } from '@ionic/cloud-angular';

const cloudSettings: CloudSettings = {
  'core': {
    'app_id': 'd32c02d2'
  },
  'auth': {
    'facebook': {
      'scope': ['public_profile', 'email']
    }
  }
};

@NgModule({
  declarations: [
   ],
  imports: [
    CloudModule.forRoot(cloudSettings)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
   ],
  providers: [

  ]
})
export class AppModule { }

home.html

 <button ion-button block type="button" (click)="fbLogin()">Fb Login</button>

home.ts

import { Component } from '@angular/core';
import { FacebookAuth, User } from '@ionic/cloud-angular';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public facebookAuth: FacebookAuth, public user: User) {

  }

  fbLogin() {
    this.facebookAuth.login();
  }

}


回答2:

Ok it's quite silly, but the first root cause was that the FB user I was trying to log in with was not registered as a tester. Apparently in that case, an empty error is returned by the plugin.

After adding as a tester, I received a real error (Andoird manifest dod not allow internet access). After fixing that issue, again I'm getting an empty error.

So my assumption is that some of the errors returned by FB are not well communicated by the plugin and so any other FB error can be causing this issue.

UPDATE 23/04: There seems to be a change from FB side, now the FB login screen did not succeed but gave an error about the hashing key. After fixing that issue, the FB login is working now.