react-native - 使用 Facebook 登录时不会触发 onLoginFinished 回调

标签 react-native react-native-fbsdk

我正在构建一个简单的 React Native 应用程序,它使用 react-native-fbsdk 实现“使用 Facebook 登录”
当使用凭据登录时,当按钮从登录更改为注销时,我可以登录和注销,但是 onLoginFinished回调永远不会被触发,尽管 onLogoutFinished工作正常。

这是我的代码:

import React, { Component } from 'react';
import { View,Alert,Button,Text } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';

export default class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userInfo: null
    }
  }

  onFacebookLoginFinished = (error, result) => {
    if (error) {
      Alert.alert("login has error: " + result.error);
    } else if (result.isCancelled) {
      Alert.alert("login is cancelled.");
    } else {
      AccessToken.getCurrentAccessToken().then(
        (data) => {
          Alert.alert(data.accessToken.toString())
          this.props.navigation.navigate('Home')
        }
      )
    }
  }

  render() {
    return (
      <View>
        <LoginButton
          onLoginFinished={this.onFacebookLoginFinished}
          onLogoutFinished={() => Alert.alert("logout.")}/>
      </View>
    );
  }
};

最佳答案

我想你应该试试这个。

onLoginFinished={(error, result) => this.onFacebookLoginFinished(error, result)}

把函数改成这个。
onFacebookLoginFinished (error, result){
    ...
}

关于react-native - 使用 Facebook 登录时不会触发 onLoginFinished 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58257093/

相关文章:

javascript - Facebook 登录不断重复询问权限 React Native?

ios - 为什么 Flatlist 中的图像有时无法渲染?

react-native - 使用官方 fbsdk 响应 native Facebook 登录

android - 在 IOS 和 Android 上 react native fbsdk 用户更改问题

android - React native fbsdk : Could not invoke FBGraphRequest. 在 android 上启用 multidex React native app 时启动

react-native - LoginManager.logInWithReadPermissions 没有在react-native-fsdk 中调用回调

reactjs - 如何在 React Native webview 中使用 PostMessage?

facebook - 警告 : Each child in an array or iterator should have a unique "key" prop. 检查 `ListView` 的渲染方法

reactjs - 为什么只有一个屏幕代码的expo apk文件很大?

javascript - 要求 Prop 不起作用。 "Invalid call at.."