패키지, 저장소 및 앱 카테고리 검색

패키지 상세v3.0.0

flutter_facebook_login

사용자가 네이티브 Android 및 iOS Facebook 로그인 SDK를 사용하여 인증할 수 있도록 해주는 플러터 플러그인입니다.

30일 다운로드
972
좋아요
408
Pub 점수
40

패키지 설치

flutter pub add flutter_facebook_login

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

공식 Facebook SDK를 사용하여 Android 및 iOS에서 네이티브 Facebook 로그인 인증을 가능하게 하는 플러터 플러그인입니다. Facebook 인증 흐름의 통합을 간소화하여 사용자가 안전하게 자신의 Facebook 계정으로 로그인할 수 있도록 합니다. 플러그인은 토큰 관리를 처리하고 성공적인 로그인 후 사용자 프로필 데이터에 접근할 수 있도록 제공합니다. 소셜 로그인 기능을 필요로 하는 플러터 애플리케이션 내에서 원활한 사용을 위해 설계되었습니다.

사용 사례

  • 소셜 로그인 통합
  • 페이스북을 통한 사용자 인증
  • 프로필 데이터 검색
  • 모바일 앱 온보딩
  • 단일 로그인 (SSO) 지원
  • 크로스 플랫폼 인증

주요 기능

  • 네이티브 SDK 통합
  • 토큰 관리
  • 사용자 프로필 접근
  • 크로스 플랫폼 지원
  • 간단한 API 인터페이스
  • 보안 인증 흐름

적합한 대상

  • Facebook 로그인을 필요로 하는 앱
  • 소셜 기능을 구축하는 개발자
  • 보안 인증이 필요한 프로젝트
  • 안드로이드 및 iOS를 대상으로 한 모바일 앱
  • 소셜 로그인을 통합하는 스타트업

고려 사항

  • Facebook 앱 ID 설정이 필요합니다
  • 플랫폼별 구성이 필요합니다
  • Facebook SDK 버전에 따라 다릅니다
  • 추가 권한이 필요할 수 있습니다
  • 웹 플랫폼에 적합하지 않습니다
  • Facebook 정책 준수

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

flutter_facebook_login

pub package Build Status Coverage Status

A Flutter plugin for using the native Facebook Login SDKs on Android and iOS.

AndroidX support

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.

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.

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.

<your project root>/android/app/src/main/res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">Your App Name here.</string>

    <!-- Replace "000000000000" with your Facebook App ID here. -->
    <string name="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.
    -->
    <string name="fb_login_protocol_scheme">fb000000000000</string>
</resources>

Then you'll just have to copy-paste the following to your Android Manifest:

<your project root>/android/app/src/main/AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />

<activity
    android:name="com.facebook.CustomTabActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="@string/fb_login_protocol_scheme" />
    </intent-filter>
</activity>

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) {
  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:

// 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.

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.

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:

android.useAndroidX=true
android.enableJetifier=true

For more, see "AndroidX compatibility" in the official Flutter documentation.

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트