Migrationsleitfaden von @capacitor-community/facebook-login zu @capgo/capacitor-social-login
Übersicht
Section titled “Übersicht”Dieser Leitfaden bietet umfassende Anweisungen für die Migration von @capacitor-community/facebook-login zu @capgo/capacitor-social-login. Das neue Plugin modernisiert die Facebook-Authentifizierung mit einer einheitlichen API, die mehrere soziale Anbieter unterstützt, verbesserte TypeScript-Unterstützung und erweiterte Funktionen bietet.
Installation
Section titled “Installation”-
Entfernen Sie das alte Paket:
Terminal-Fenster npm uninstall @capacitor-community/facebook-login -
Installieren Sie das neue Paket:
Terminal-Fenster npm install @capgo/capacitor-social-loginnpx cap sync
Code-Änderungen
Section titled “Code-Änderungen”Import-Änderungen
Section titled “Import-Änderungen”import { FacebookLogin } from '@capacitor-community/facebook-login';import { SocialLogin } from '@capgo/capacitor-social-login';Initialisierung
Section titled “Initialisierung”Wichtige Änderung: Das neue Paket erfordert eine explizite Einrichtung in Ihrem Code:
// Altes Paket erforderte keine explizite Initialisierung im Code// Konfiguration erfolgte nur auf nativen Plattformen
// Neues Paket erfordert explizite Initialisierungawait SocialLogin.initialize({ facebook: { appId: 'YOUR_FACEBOOK_APP_ID', // Erforderlich für Web und Android clientToken: 'YOUR_CLIENT_TOKEN' // Erforderlich für Android }});Die Login-Methode akzeptiert jetzt einen Provider-Parameter:
const FACEBOOK_PERMISSIONS = ['email', 'public_profile'];const result = await FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS });
const result = await SocialLogin.login({ provider: 'facebook', options: { permissions: ['email', 'public_profile'], limitedLogin: false, nonce: 'optional_nonce' }});Änderungen des Antworttyps
Section titled “Änderungen des Antworttyps”Die Antwortstruktur wurde mit einem umfassenderen Profilobjekt modernisiert:
// Alter Antworttypinterface FacebookLoginResponse { accessToken: { applicationId: string; userId: string; token: string; expires: string; }; recentlyGrantedPermissions: string[]; recentlyDeniedPermissions: string[];}
// Neuer Antworttypinterface FacebookLoginResponse { provider: 'facebook'; result: { accessToken: { token: string; applicationId?: string; expires?: string; userId?: string; permissions?: string[]; declinedPermissions?: string[]; } | null; idToken: string | null; profile: { userID: string; email: string | null; friendIDs: string[]; birthday: string | null; ageRange: { min?: number; max?: number } | null; gender: string | null; location: { id: string; name: string } | null; hometown: { id: string; name: string } | null; profileURL: string | null; name: string | null; imageURL: string | null; }; };}Hauptunterschiede:
- Die Antwort enthält jetzt ein
provider-Feld zur Identifizierung des Authentifizierungsanbieters - Detaillierteres
profile-Objekt mit zusätzlichen Benutzerinformationen - Konsistente Struktur über alle sozialen Login-Anbieter hinweg
Login-Status überprüfen
Section titled “Login-Status überprüfen”const result = await FacebookLogin.getCurrentAccessToken();const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({ provider: 'facebook'});const isLoggedIn = status.isLoggedIn;Logout
Section titled “Logout”await FacebookLogin.logout();
await SocialLogin.logout({ provider: 'facebook'});Plattformspezifische Änderungen
Section titled “Plattformspezifische Änderungen”Android-Einrichtung
Section titled “Android-Einrichtung”Die Konfiguration erfolgt jetzt über die Initialize-Methode:
// AndroidManifest.xml-Änderungen bleiben gleich// strings.xml wird irrelevant// Zusätzlich in Ihrem Code initialisieren:await SocialLogin.initialize({ facebook: { appId: 'your-app-id', clientToken: 'your-client-token' // Neue Anforderung }});Wichtig: Client-Token ist jetzt für die Android-Authentifizierung erforderlich.
iOS-Einrichtung
Section titled “iOS-Einrichtung”- Die iOS-Einrichtung in
AppDelegate.swiftbleibt gleich:
import FBSDKCoreKit
// In application:didFinishLaunchingWithOptions:FBSDKCoreKit.ApplicationDelegate.shared.application( application, didFinishLaunchingWithOptions: launchOptions)
// In application:openURL:options:ApplicationDelegate.shared.application( app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation])- Die
Info.plist-Konfiguration bleibt gleich:
<key>CFBundleURLTypes</key><array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb[APP_ID]</string> </array> </dict></array><key>FacebookAppID</key><string>[APP_ID]</string><key>FacebookClientToken</key><string>[CLIENT_TOKEN]</string><key>FacebookDisplayName</key><string>[APP_NAME]</string><key>LSApplicationQueriesSchemes</key><array> <string>fbapi</string> <string>fbauth</string> <string>fb-messenger-share-api</string> <string>fbauth2</string> <string>fbshareextension</string></array>Breaking Changes
Section titled “Breaking Changes”Zusammenfassung der Breaking Changes bei der Migration:
- Explizite Initialisierung ist jetzt erforderlich - Muss
initialize()vor der Verwendung aufrufen - Struktur des Antwortobjekts hat sich erheblich geändert - Neues verschachteltes Ergebnisformat mit erweiterten Profildaten
- Client-Token ist jetzt für Android erforderlich - Zusätzliche Konfiguration erforderlich
- Unterschiedliche Methodennamen und Parameterstrukturen - Provider-basierter Ansatz
- Fehlerbehandlung und Fehlertypen haben sich geändert - Detailliertere Fehlerinformationen
Hauptvorteile
Section titled “Hauptvorteile”Das neue Plugin bietet:
- Einheitliche API über mehrere soziale Anbieter hinweg (Google, Apple, Facebook)
- Verbesserte TypeScript-Unterstützung mit besseren Typdefinitionen
- Erweiterte Profildaten mit mehr Benutzerinformationen
- Aktive Wartung und Community-Support
- Konsistente Fehlerbehandlung über alle Anbieter hinweg
- Bessere Token-Verwaltung mit ordnungsgemäßer Ablaufbehandlung
Für detailliertere Einrichtungsanweisungen konsultieren Sie bitte die offizielle Dokumentation.