React Native Facebook SDK,登录随机失败

问题描述 投票:0回答:2

我正在将react-native-fbsdk 0.8.0与React-Native 0.57.4一起使用,并得到错误:

登录失败并显示错误:操作无法完成。(com.facebook.sdk.login错误308)。

大约30%的时间。我已经尝试过LoginButton和LoginManager。

还尝试了react-native-fbsdk的v0.9和v0.7,结果相同。

[使用LoginManager,我也尝试了其他人(例如https://medium.com/@crysfel/error-when-login-with-facebook-sdk-react-native-c06a33078102)发布的LoginManager.logOut()技巧

我已启用了钥匙串共享功能。

我已按照https://github.com/facebook/react-native-fbsdk的所有说明进行操作,包括设置LSApplicationQueriesSchemes

如果它能正常工作2/3次,我应该如何尝试下一步建议?

我的登录按钮代码:

            <LoginButton
          style={[styles.button, styles.facebook]}
          readPermissions={[
            'public_profile',
            'user_birthday',
            'user_gender',
            'email'
          ]}
          onLoginFinished={(error, result) => {
            if (error) {
              alert('Login failed with error: ' + error.message);
            } else if (result.isCancelled) {
              alert('Login was cancelled');
            } else {
              // alert(
              //   'Login was successful with permissions: ' +
              //     result.grantedPermissions
              // );
              AccessToken.getCurrentAccessToken().then(data => {
                console.log(data.accessToken.toString());
                this.fetchProfile().then(profile =>
                  this.checkOrAddUser(profile)
                );
              });
            }
          }}
          onLogoutFinished={() => alert('User logged out')}
        />

和我的LoginManager代码:

  handleLogin = () => {
    LoginManager.logInWithReadPermissions([
      'public_profile',
      'user_birthday',
      'user_gender',
      'email'
    ]).then(
      result => {
        if (result.isCancelled) {
          console.log(result);
          console.log('Login cancelled');
        } else {
          console.log(
            'Login success with permissions: ' +
              result.grantedPermissions.toString()
          );
          console.log('result is ' + result);
          AccessToken.getCurrentAccessToken().then(data => {
            console.log(data.accessToken.toString());
            this.fetchProfile().then(profile => this.checkOrAddUser(profile));
          });
        }
      },
      function(error) {
        console.log(error);
        console.log('Login fail with error: ' + error.message);
        LoginManager.logOut();
        alert('Login failed. Try again.');
      }
    );
  };
react-native fbsdk react-native-fbsdk
2个回答
0
投票

通过执行该线程末尾的步骤,我能够在iOS上解决此问题:https://github.com/facebook/facebook-swift-sdk/issues/286

即,将这些行添加到我的Podfile中

pod 'FacebookSDK', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKCoreKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKShareKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKLoginKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'

并删除我手动添加到“使用库链接二进制文件”部分的FBSDK .framework文件,运行“ pod install”,然后清理构建和派生数据文件夹。


0
投票

希望这会有所帮助。

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

export default class Login extends Component {
  render() {
    return (
      <View style={{flex: 1, flexDirection: 'column'}}>
        <LoginButton
          onLoginFinished={
            (error, result) => {
              if (error) {
                console.log("login has error: " + result.error);
              } else if (result.isCancelled) {
                console.log("login is cancelled.");
              } else {
                AccessToken.getCurrentAccessToken().then(
                  (data) => {
                    console.log(data.accessToken.toString())
                  }
                )
              }
            }
          }
          onLogoutFinished={() => console.log("logout.")}/>

      </View>
    );
  }
};
© www.soinside.com 2019 - 2024. All rights reserved.