name27 / flutter

0 stars 0 forks source link

facebook 로그인 추가 #113

Open name27 opened 1 year ago

name27 commented 1 year ago

설정 패키지 이름: android/app/build.gradle

defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.day_34_test_firebase" //패키지 이름

기본 액티비티 클래스 이름: 패키지 이름 + .MainActivity

keytool 만들기

C:\>keytool -genkey -v -keystore c:/Users/USER_NAME/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:
What is the name of your organizational unit?
  [Unknown]:
What is the name of your organization?
  [Unknown]:
What is the name of your City or Locality?
  [Unknown]:
What is the name of your State or Province?
  [Unknown]:
What is the two-letter country code for this unit?
  [Unknown]:
Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
  [no]:  y

키 해시 구하는 명령어

C:\Program Files\Android\Android Studio\jre\bin>keytool -exportcert -alias key -keystore C:\Users\c\key.jks | "C:\Users\c\openssl-0.9.8e_X64\bin\openssl" sha1 -binary | "C:\Users\c\openssl-0.9.8e_X64\bin\openssl" base64

android / app / src / main / res / values 에 strings.xml 만들기

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">app_name</string>
    <string name="facebook_app_id">여기는 앱 아이디</string>
    <string name="fb_login_protocol_scheme">fb + 앱 아이디</string>
    <string name="facebook_client_token">토큰값</string>
</resources>

토근 값: 대시보드 설정 / 고급설정 / 클라이언트 토큰

android / app / src / main / AndroidManifest.xml 에

정확하지 않은 코드 포함

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.day_34_test_firebase">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>
   <application
        android:label="day_34_test_firebase"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/facebook_app_id" />
        <meta-data
            android:name="com.facebook.sdk.ClientToken"
            android:value="@string/facebook_client_token" />

        <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>
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

Facebook 로그인 / 설정

image

name27 commented 1 year ago

firebase - flutter - 제휴 ID 및 소셜 로그인

Future<UserCredential> signInWithFacebook() async {
  // Trigger the sign-in flow
  final LoginResult loginResult = await FacebookAuth.instance.login();

  // Create a credential from the access token
  final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);

  // Once signed in, return the UserCredential
  return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}
name27 commented 1 year ago

image

Apps that target Android API 30+ (Android 11+) cannot call Facebook native apps unless the package visibility needs are declared. Please follow https://developers.facebook.com/docs/android/troubleshooting/#faq_267321845055988 to make the declaration. 이 url로 넘어가면 이 화면이 나오는데 image image 나오는 대로 해도 해결이 안된다.