Zum Inhalt springen

Facebook Login Migration zu @capgo/social-login

@GitHub

Diese Anleitung bietet umfassende Anweisungen zur Migration von @capacitor-community/facebook-login Live-Updates @capgo/capacitor-social-login. Die 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

Installation
  1. Entfernen Sie das alte Paket:

    Terminal-Fenster
    npm uninstall @capacitor-community/facebook-login
  2. Installieren Sie das neue Paket:

    Terminal-Fenster
    npm install @capgo/capacitor-social-login
    npx cap sync

Änderungen importieren

Terminal-Fenster
import { FacebookLogin } from '@capacitor-community/facebook-login';
import { SocialLogin } from '@capgo/capacitor-social-login';

Schlüsseländerung: Die neue Paket erfordert eine explizite Einrichtung in Ihrem code:

// Old package required no explicit initialization in code
// Configuration was done only in native platforms
// New package requires explicit initialization
await SocialLogin.initialize({
facebook: {
appId: 'YOUR_FACEBOOK_APP_ID', // Required for web and Android
clientToken: 'YOUR_CLIENT_TOKEN' // Required for Android
}
});

Die Anmelde Methode akzeptiert nun 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'
}
});

Die Antwortstruktur wurde mit einer umfassenderen Profilobjekt modernisiert:

// Old response type
interface FacebookLoginResponse {
accessToken: {
applicationId: string;
userId: string;
token: string;
expires: string;
};
recentlyGrantedPermissions: string[];
recentlyDeniedPermissions: string[];
}
// New response type
interface 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;
};
};
}

Schlüsselunterschiede:

  • Die Antwort enthält nun ein Feld, das den Authentifizierungsanbieter identifiziert provider Mehr detaillierte
  • Objekt mit zusätzlichen Benutzerinformationen profile Konsistente Struktur bei allen sozialen Anmeldeanbietern
  • Überprüfung der Anmeldestatus

Abschnitt mit dem Titel „Überprüfung des Anmeldestatus“

Auf die Zwischenablage kopieren
const result = await FacebookLogin.getCurrentAccessToken();
const isLoggedIn = result && result.accessToken;
const status = await SocialLogin.isLoggedIn({
provider: 'facebook'
});
const isLoggedIn = status.isLoggedIn;

protectedTokens

Ausloggen
await FacebookLogin.logout();
await SocialLogin.logout({
provider: 'facebook'
});

Plattformspezifische Änderungen

Abschnitt: Plattformspezifische Änderungen

Die Konfiguration wird nun über die initialize-Methode gehandhabt:

// AndroidManifest.xml changes remain the same
// strings.xml become irrelevant
// Additionally initialize in your code:
await SocialLogin.initialize({
facebook: {
appId: 'your-app-id',
clientToken: 'your-client-token' // New requirement
}
});

WichtigKunden-Token ist nun für die Android-Authentifizierung erforderlich.

  1. Die iOS-Einrichtung in AppDelegate.swift bleibt 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]
)
  1. 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>

Zusammenfassung der Änderungen mit Auswirkungen auf die Kompatibilität bei der Migration:

  1. Die explizite Initialisierung ist jetzt erforderlich - Muss vor der Verwendung aufgerufen werden initialize() __CAPGO_KEEP_0__
  2. Die Struktur des Antwortobjekts hat sich erheblich geändert - Neuer, verschachtelter Ergebnisformat mit erweiterten Profildaten
  3. - Client-Token ist nun für Android erforderlich - Zusätzliche Konfiguration erforderlich
  4. - Änderungen bei den Methodennamen und den Parameterstrukturen - Anbieterbasierte Ansätze
  5. - Fehlerbehandlung und Fehlerarten haben sich geändert - Detailliertere Fehlerinformationen

Das neue Plugin bietet:

  • Einheitliche API über mehrere soziale Anbieter (Google, Apple, Facebook)
  • __CAPGO_KEEP_0__ __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__ __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__ __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__ __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__ __CAPGO_KEEP_0__

für weitere detaillierte Anweisungen zur Einrichtung, zögern Sie bitte nicht, auf die Migrations zur sozialen Anmeldung.

Fortsetzung von der Migrations zur sozialen Anmeldung von Facebook zu @capgo/soziale-Anmeldung

Abschnitt mit dem Titel “Fortsetzung von der Migrations zur sozialen Anmeldung von Facebook zu @capgo/soziale-Anmeldung”

Wenn Sie die Migrations zur sozialen Anmeldung von Facebook verwenden Facebook Login Migration to @capgo/social-login um die Authentifizierung und die Kontenflüsse zu planen, verbinden Sie es mit Verwendung von @capgo/capacitor-soziale-Anmeldung für die native Fähigkeit in Verwendung von @capgo/capacitor-soziale-Anmeldung @capgo/capacitor-soziale-Anmeldung für die Implementierungsdetails in @capgo/capacitor-soziale-Anmeldung @capgo/capacitor-Passwort für die Implementierungsdetails in @capgo/capacitor-Passwort @capgo/capacitor-native-biometric für die Implementierungsdetails in @capgo/capacitor-native-biometric, und Zweifaktor-Authentifizierung für die Implementierungsdetails in Zweifaktor-Authentifizierung.