Overview
This guide will walk you through implementing Facebook Login in your React Native app. You’ll learn how to:- Initialize the Facebook SDK
- Add a Facebook Login button
- Handle login callbacks
- Access user information
Make sure you’ve completed the Installation guide before proceeding.
Step 1: Initialize the SDK
Before using any Facebook SDK features, you need to initialize it. Add this code to your app’s entry point (usuallyApp.js or App.tsx):
Why initialize the SDK?
Why initialize the SDK?
Starting with iOS SDK v9.0.0, Facebook removed automatic initialization to comply with Apple’s privacy requirements. You must explicitly initialize the SDK before using any Facebook features.For GDPR compliance, you may want to delay initialization until after obtaining user consent.
Step 2: Add Facebook Login Button
TheLoginButton component provides a ready-to-use Facebook-branded login button:
App.js
The LoginButton automatically shows “Log in with Facebook” when logged out and “Log out” when logged in.
Step 3: Request Specific Permissions
By default, the login button requestspublic_profile permission. To request additional permissions:
Step 4: Get Access Token
After a successful login, retrieve the access token to make Graph API requests:Step 5: Fetch User Profile
Use the Graph API to retrieve user information:The
email field requires the email permission to be granted by the user.Step 6: Use Login Manager (Programmatic Login)
For custom UI, use theLoginManager instead of the LoginButton:
iOS: Limited Login
With Limited Login, you receive anAuthenticationToken instead of an AccessToken:
An
AuthenticationToken (from Limited Login) cannot be used to access the Facebook Graph API. It’s an OpenID Connect token used for authentication only.Complete Working Example
Here’s a full example combining all the concepts:Testing Your Integration
Verify Login Flow
- Tap the Facebook Login button
- Complete the authentication flow
- Verify that user data is displayed correctly
- Test logout functionality
Troubleshooting
Login button doesn't respond
Login button doesn't respond
'Invalid OAuth access token' error
'Invalid OAuth access token' error
This error occurs when:
- Using an
AuthenticationToken(from Limited Login) with Graph API - Access token has expired
- Facebook App is in Development mode and the user is not a tester/admin
loginTrackingIOS="enabled" for standard login with Graph API access.Email field is null
Email field is null
- Ensure you’ve requested the
emailpermission - User must approve the email permission
- Some users may not have an email associated with their Facebook account
App crashes on iOS
App crashes on iOS
- Verify you’ve added the
openURLmethod in AppDelegate - Check that Facebook App ID is in Info.plist
- Ensure CocoaPods dependencies are properly installed
Next Steps
Sharing Content
Learn how to share links, photos, and videos to Facebook
Graph API
Make advanced requests to Facebook’s Graph API
App Events
Track user actions and conversions for analytics
Advanced Login
Implement custom login flows and handle permissions