尝试与我的本机代码与Facebook错误集成时-“您尚未登录。请登录并重试”

时间:2019-01-03 07:08:39

标签: android reactjs react-native facebook-javascript-sdk

我是本机反应的新手,我正在尝试在我的应用程序中实现Facebook登录功能。到目前为止,我已经完成了https://github.com/facebook/react-native-fbsdk所述的所有必要步骤。

我要实现的是代替此错误页面,用户应该导航到Facebook登录页面。

Here's the snapshot of error

// FBLoginButton.js
     export default class FBLoginButton extends Component {

              fbAuth() {
                LoginManager.logInWithReadPermissions(['public_profile']).then(
                  (result) => {
                    if (result.isCancelled) {
                      console.log('Login Failed');
                      console.log(result);
                    } else {
                      console.log('Login Success');
                      console.log(result.grantedPermissions.toString());
                    }
                  },
                  (error) => {
                    console.log(`An Error has occured!  ${error}`);
                  });
              }

              render() {
                return (
                  <View>
                    <TouchableOpacity onPress={this.fbAuth} >
                    <Text>
                      Facebook
                    </Text>
                    </TouchableOpacity>
                  </View>
                );
              }

            }

//MainActivity.java            
            public class MainActivity extends ReactActivity {

                /**
                 * Returns the name of the main component registered from JavaScript.
                 * This is used to schedule rendering of the component.
                 */
                @Override
                protected String getMainComponentName() {
                    return "Flewber";
                }

                @Override
                public void onActivityResult(int requestCode, int resultCode, Intent data) {
                    super.onActivityResult(requestCode, resultCode, data);
                    MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
                }
            }

//MainApplication .java
            public class MainApplication extends Application implements ReactApplication {


             private static CallbackManager mCallbackManager = CallbackManager.Factory.create();

              protected static CallbackManager getCallbackManager() {
                return mCallbackManager;
              }

              private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
                @Override
                public boolean getUseDeveloperSupport() {
                  return BuildConfig.DEBUG;
                }

                @Override
                protected List<ReactPackage> getPackages() {
                  return Arrays.<ReactPackage>asList(
                      new MainReactPackage(),
                      new FBSDKPackage(mCallbackManager)
                  );
                }
            };

              @Override
              public ReactNativeHost getReactNativeHost() {
                return mReactNativeHost;
              }

              @Override
              public void onCreate() {
                super.onCreate();
                AppEventsLogger.activateApp(this);

              }
            }

0 个答案:

没有答案