Aus öffentlichen Paketdaten erstellte Orientierung.
Ein Flutter-Plugin, das die native Facebook-Anmeldung auf Android und iOS mithilfe der offiziellen Facebook SDKs ermöglicht. Es vereinfacht die Integration des Facebook-Authentifizierungsflusses und ermöglicht es Benutzern, sicher mit ihren Facebook-Konten einzuloggen. Das Plugin verwaltet Tokens und bietet Zugriff auf Benutzerprofil-Daten nach erfolgreicher Anmeldung. Es ist für nahtlose Nutzung innerhalb von Flutter-Anwendungen mit sozialen Login-Funktionen konzipiert.
Anwendungsfälle
Soziale Anmeldung Integration
Benutzerauthentifizierung über Facebook
Abruf von Profildaten
Mobile-App-Onboarding
Unterstützung für Single Sign-On (SSO)
Plattformübergreifende Authentifizierung
Hauptmerkmale
Native SDK-Integration
Token-Verwaltung
Benutzerprofil-Zugriff
Plattformübergreifende Unterstützung
Einfache API-Schnittstelle
Sichere Authentifizierungsablauf
Geeignet für
Apps, die Facebook-Anmeldung erfordern
Entwickler, die soziale Funktionen erstellen
Projekte, die sichere Authentifizierung benötigen
Mobile Apps für Android & iOS
Startups, die soziale Anmeldung integrieren
Hinweise
Facebook-App-ID-Einrichtung erforderlich
Benötigt plattformspezifische Konfiguration
Abhängig von Facebook SDK-Versionen
Könnte zusätzliche Berechtigungen erfordern
Nicht geeignet für Webplattformen
Einhaltung der Richtlinien von Facebook
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
flutter_facebook_login
A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.
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.
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.
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.
<?xml version="1.0" encoding="utf-8"?><resources><stringname="app_name">Your App Name here.</string><!-- Replace "000000000000" with your Facebook App ID here. --><stringname="facebook_app_id">000000000000</string><!--
Replace "000000000000" with your Facebook App ID here.
**NOTE**: The scheme needs to start with `fb` and then your ID.
--><stringname="fb_login_protocol_scheme">fb000000000000</string></resources>
Then you'll just have to copy-paste the following to your Android Manifest:
A sample of a complete AndroidManifest file can be found here.
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.
(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 </dict></plist> 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).
<your project root>/ios/Runner/Info.plist
<key>CFBundleURLTypes</key><array><!--
<dict>
... Some other CFBundleURLTypes definition.
</dict>
--><dict><key>CFBundleURLSchemes</key><array><!--
Replace "000000000000" with your Facebook App ID here.
**NOTE**: The scheme needs to start with `fb` and then your ID.
--><string>fb000000000000</string></array></dict></array><key>FacebookAppID</key><!-- Replace "000000000000" with your Facebook App ID here. --><string>000000000000</string><key>FacebookDisplayName</key><!-- Replace "YOUR_APP_NAME" with your Facebook App name. --><string>YOUR_APP_NAME</string><key>LSApplicationQueriesSchemes</key><array><string>fbapi</string><string>fb-messenger-share-api</string><string>fbauth2</string><string>fbshareextension</string></array>
A sample of a complete Info.plist file can be found here.
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. Everything is documented there.
Since sample code is worth more than one page of documentation, here are the usual cases covered:
import'package:flutter_facebook_login/flutter_facebook_login.dart';
final facebookLogin = FacebookLogin();
final result = await facebookLogin.logIn(['email']);
switch (result.status) {
caseFacebookLoginStatus.loggedIn:
_sendTokenToServer(result.accessToken.token);
_showLoggedInUI();
break;
caseFacebookLoginStatus.cancelledByUser:
_showCancelledMessage();
break;
caseFacebookLoginStatus.error:
_showErrorOnUI(result.errorMessage);
break;
}
You can also change the visual appearance of the login dialog. For example:
// Let's force the users to login using the login dialog based on WebViews. Yay!
facebookLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;
For now, this feature isn't going to be integrated into this plugin. See the discussion here.
However, you can get do this in four lines of Dart code:
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:
{"name":"Iiro Krankka","first_name":"Iiro","last_name":"Krankka","email":"iiro.krankka\u0040gmail.com","id":"<user id here>"}
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: