Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use facebook login with Create-react-native-app

I try to find a way to use Facebook login with Create-react-native-app for both Android and IOS. Is that possible? All this seem pretty new...

like image 232
mb3 Avatar asked Aug 19 '17 02:08

mb3


People also ask

How do I integrate Facebook Login API to my React app?

To integrate Facebook Login into a website or application you need to create a Facebook App at https://developers.facebook.com/apps/ and set up the Facebook Login product under the App. Creating a Facebook App will provide you with a Facebook App ID which is required when initializing the Facebook JavaScript SDK ( FB.

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.

Does Facebook use React Native for their app?

Originally, Facebook only developed React Native to support iOS. However, with it's recent support of the Android operating system, the library can now provide mobile UIs for both platforms. Facebook used React Native to develop its own Ads Manager app, creating both an iOS and an Android version.


1 Answers

Use the Expo SDK. This way you won't have to eject from create-react-native-app.

import { Facebook } from 'expo';

async function logIn() {
  const { type, token } = await Facebook.logInWithReadPermissionsAsync('<APP_ID>', {
    permissions: ['public_profile'],
  });

  if (type === 'success') {
    // Get the user's name using Facebook's Graph API
    const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`);

    Alert.alert(
      'Logged in!',
      `Hi ${(await response.json()).name}!`,
    );
  }
}

Snippet taken from the link.

like image 166
fxlemire Avatar answered Oct 27 '22 12:10

fxlemire