Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Facebook Login using official fbsdk

I tried following the starter tutorial by setting up a new React Native Project for iOS. But the loginbutton doesn't seem to be working. Any help is appreciated.

Here's the index.ios.js:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

const FBSDK = require('react-native-fbsdk');
const {
  LoginButton
} = FBSDK;

var Login = React.createClass({
  render: function() {
    return (
      <View>
        <LoginButton
          publishPermissions={["publish_actions"]}
          onLoginFinished={
            (error, result) => {
              if (error) {
                alert("login has error: " + result.error);
              } else if (result.isCancelled) {
                alert("login is cancelled.");
              } else {
                alert("login has finished with permissions: " + result.grantedPermissions)
              }
            }
          }
          onLogoutFinished={() => alert("logout.")}/>
      </View>
    );
  }
});

class AwesomeProject extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
          Login to Facebook
        </Text>
        <Login />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  shareText: {
    fontSize: 20,
    margin: 10,
  }
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

And the screenshot of the emulator: enter code here

like image 841
philoniare Avatar asked May 14 '16 18:05

philoniare


People also ask

How do you implement Facebook Login in React Native with Firebase?

Before getting started, ensure you have installed the library, configured your Android & iOS applications and setup your Facebook Developer Account to enable Facebook Login. Ensure the "Facebook" sign-in provider is enabled on the Firebase Console.

Will Facebook stop supporting React Native?

Facebook SDK for React NativeAs of January 19, 2021, Facebook React Native SDK will no longer be officially supported by Facebook.


1 Answers

You need to link the sdk's iOS project in your app's project.

If you're using react-native-sdk v0.2.0+, rnpm will take care of this step and you can follow the tips here to complete set up.

If you're using the older version, you need to link react-native-fbsdkxxx.xcodeproj in YourApp.xcodeproj. Follow the manual linking steps in https://facebook.github.io/react-native/docs/linking-libraries-ios.html

like image 149
dzhuowen Avatar answered Oct 03 '22 14:10

dzhuowen