Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/roughike/flutter_facebook_login
A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.
https://github.com/roughike/flutter_facebook_login
dart facebook-login flutter flutter-plugin
Last synced: about 2 months ago
JSON representation
A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs.
- Host: GitHub
- URL: https://github.com/roughike/flutter_facebook_login
- Owner: roughike
- License: bsd-2-clause
- Created: 2018-01-24T13:28:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-30T07:58:33.000Z (about 3 years ago)
- Last Synced: 2024-01-11T04:45:18.509Z (5 months ago)
- Topics: dart, facebook-login, flutter, flutter-plugin
- Language: Dart
- Size: 169 KB
- Stars: 402
- Watchers: 19
- Forks: 331
- Open Issues: 163
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Lists
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter-cn - Facebook Login - 使用原生Android和iOS的Facebook登录SDK进行身份验证 [Iiro Krankka](https://github.com/roughike)。 (组件 / 验证)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- -awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter-cn - Facebook Login - 使用原生 Android & iOS Facebook 登录 SDKs 身份验证,[Iiro Krankka](https://github.com/roughike). (组件 / 身份验证)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- awesome-flutter - Facebook Login - Authenticate with native Android & iOS Facebook login SDKs by [Iiro Krankka](https://github.com/roughike). (Components / Auth)
- my-awesome-stars - roughike/flutter_facebook_login - A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs. (Dart)
- awesome-flutter - Facebook Login - A Flutter plugin for allowing users to authenticate with native Android & iOS Facebook login SDKs. ` 📝 10 months ago ` (Auth [🔝](#readme))
README
# flutter_facebook_login
[![pub package](https://img.shields.io/pub/v/flutter_facebook_login.svg)](https://pub.dartlang.org/packages/flutter_facebook_login)
[![Build Status](https://travis-ci.org/roughike/flutter_facebook_login.svg?branch=master)](https://travis-ci.org/roughike/flutter_facebook_login)
[![Coverage Status](https://coveralls.io/repos/github/roughike/flutter_facebook_login/badge.svg)](https://coveralls.io/github/roughike/flutter_facebook_login)A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.
## AndroidX support
* if you want to **avoid AndroidX**, use version 1.2.0.
* for [AndroidX Flutter projects](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility), use versions 2.0.0 and up.## Installation
To get things up and running, you'll have to declare a pubspec dependency in your Flutter project.
Also some minimal Android & iOS specific configuration must be done, otherwise your app will crash.### On your Flutter project
See the [installation instructions on pub](https://pub.dartlang.org/packages/flutter_facebook_login#-installing-tab-).
### Android
This assumes that you've done the _"Associate Your Package Name and Default Class with Your App"_ and
_"Provide the Development and Release Key Hashes for Your App"_ in the [the Facebook Login documentation for Android site](https://developers.facebook.com/docs/facebook-login/android).After you've done that, find out what your _Facebook App ID_ is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.
Once you have the Facebook App ID figured out, you'll have to do two things.
First, copy-paste the following to your strings resource file. If you don't have one, just create it.
**\/android/app/src/main/res/values/strings.xml**
```xml
Your App Name here.
000000000000
fb000000000000```
Then you'll just have to copy-paste the following to your _Android Manifest_:
**\/android/app/src/main/AndroidManifest.xml**
```xml
```
A sample of a complete AndroidManifest file can be found [here](https://github.com/roughike/flutter_facebook_login/blob/master/example/android/app/src/main/AndroidManifest.xml#L39-L56).
Done!
### iOS
This assumes that you've done the _"Register and Configure Your App with Facebook"_ step in the
[the Facebook Login documentation for iOS site](https://developers.facebook.com/docs/facebook-login/ios).
(**Note**: you can skip "Step 2: Set up Your Development Environment" and "Step 5: Connect Your App Delegate").After you've done that, find out what your _Facebook App ID_ is. You can find your Facebook App ID in your Facebook App's dashboard in the Facebook developer console.
Once you have the Facebook App ID figured out, then you'll just have to copy-paste the following to your _Info.plist_ file, before the ending `` tags.
(**NOTE**: If you are using this plugin in conjunction with for example `google_sign_in` plugin, which also requires you to add `CFBundleURLTypes` key into _Info.plist_ file, you need to merge them together).**\/ios/Runner/Info.plist**
```xml
CFBundleURLTypes
CFBundleURLSchemes
fb000000000000
FacebookAppID
000000000000
FacebookDisplayNameYOUR_APP_NAME
LSApplicationQueriesSchemes
fbapi
fb-messenger-share-api
fbauth2
fbshareextension```
A sample of a complete Info.plist file can be found [here](https://github.com/roughike/flutter_facebook_login/blob/master/example/ios/Runner/Info.plist#L49-L70).
Done!
## How do I use it?
The library tries to closely match the native Android & iOS login SDK APIs where possible. For complete API documentation, just see the [source code](https://github.com/roughike/flutter_facebook_login/blob/master/lib/flutter_facebook_login.dart). Everything is documented there.
Since sample code is worth more than one page of documentation, here are the usual cases covered:
```dart
import 'package:flutter_facebook_login/flutter_facebook_login.dart';final facebookLogin = FacebookLogin();
final result = await facebookLogin.logIn(['email']);switch (result.status) {
case FacebookLoginStatus.loggedIn:
_sendTokenToServer(result.accessToken.token);
_showLoggedInUI();
break;
case FacebookLoginStatus.cancelledByUser:
_showCancelledMessage();
break;
case FacebookLoginStatus.error:
_showErrorOnUI(result.errorMessage);
break;
}
```You can also change the visual appearance of the login dialog. For example:
```dart
// Let's force the users to login using the login dialog based on WebViews. Yay!
facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;
```The complete API documentation lives with the source code, [which can be found here](https://github.com/roughike/flutter_facebook_login/blob/master/lib/flutter_facebook_login.dart).
### Getting the Facebook profile of a signed in user
For now, this feature isn't going to be integrated into this plugin. See the [discussion here](https://github.com/roughike/flutter_facebook_login/issues/11).
However, you can get do this in four lines of Dart code:
```dart
final result = await facebookSignIn.logIn(['email']);
final token = result.accessToken.token;
final graphResponse = await http.get(
'https://graph.facebook.com/v2.12/me?fields=name,first_name,last_name,email&access_token=${token}');
final profile = JSON.decode(graphResponse.body);
```The `profile` variable will now contain the following information:
```json
{
"name": "Iiro Krankka",
"first_name": "Iiro",
"last_name": "Krankka",
"email": "iiro.krankka\u0040gmail.com",
"id": ""
}
```### Troubleshooting
If you haven't completed AndroidX setup in your Flutter project, your project might not build.
The simple solution is adding 2 lines in your android/gradle.properties:```
android.useAndroidX=true
android.enableJetifier=true
```For more, see ["AndroidX compatibility" in the official Flutter documentation](https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility).