ionic4 Facebook登录捕获“用户”被取消为错误

在将我的问题标记为重复之前,请注意,我也看到过类似的问题,但未正确回答,该解决方案对提出要求的人也无效,对我也不起作用。

我正在尝试实现离子本机fb登录,

我已经检查过用户是否已登录,但用户不是。请谁提供解决方案

  this.faceBook.login(['public_profile','user_friends','email'])
  .then((response: FacebookLoginResponse) => {
    this.presentToast("response");
    const facebookCredential = firebase.auth.FacebookAuthProvider.credential(
      response.authResponse.accessToken
    );
    firebase.auth().signInWithCredential(facebookCredential)
      .then(result => {
        var user = result.user;
        resolve(user);
      })
      .catch(err => {
        reject(err);
      });
  })
  .catch(err => {
    this.presentToast(err);
  });

吐司消息是“用户已取消”。我不知道为什么会这样。有人可以帮我吗

dangdangheta 回答:ionic4 Facebook登录捕获“用户”被取消为错误

尝试此操作,因为如果您已经登录,将抛出错误。您需要先检查用户是否在此处登录为示例

 this.fb.getLoginStatus().then((res) => {
  if (res.status === 'connected') {
    //console.log('connected',res);
    this.fb.api("/" + res.authResponse.userID + "/?fields=id,email,name,picture,first_name,last_name,gender",["public_profile"]).then((data) => {
      //console.log('data',data.email);

    })
    //


  } else {
    this.fb.login([]).then((userData) => {
      //console.log('note connected',userData);
      this.fb.api("/" + userData.authResponse.userID + "/?fields=id,["public_profile"]).then((data) => {
        //console.log('data',data.email);

      })
    }).catch((error) => {
      // FB Log in error

      this.util.showErrorAlert('Something went Wrong while login');
    });
  }
});
,

对我有用的是降级cordova插件。 我在项目上有这些版本:

"@ionic-native/facebook": "^4.1.0","cordova-plugin-facebook4": "^4.2.1",

我删除了^以防止进行不必要的更新,并将cordova-plugin-facebook4降级为4.1.0。

"@ionic-native/facebook": "4.1.0","cordova-plugin-facebook4": "4.1.0",

如果它不起作用,请尝试查看cordova-plugin-facebook4 github发布页面并签出变更日志。也许这会指引您正确的方向。

本文链接:https://www.f2er.com/3068491.html

大家都在问