java - 我正在使用 firebase UI 登录到我的应用程序,但是当我使用 Facebook 构建器时,它会停止应用程序如何为该按钮充气..?
问题描述
我附上了 Java 文件、依赖文件和 Manifestfile 的代码
我在外面宣布
private static final int MY_REQUEST_CODE = 123;
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build(),
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());
在这之后我提到了这个
Intent intent = AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.setLogo(R.drawable.logo)
.setTheme(R.style.LoginTheme)
.setTosAndPrivacyPolicyUrls(
"https://example.com/terms.html",
"https://example.com/privacy.html")
.build();
最后我提到了 startActivity
startActivityForResult(intent,MY_REQUEST_CODE);
现在这是我的依赖文件
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0' //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
//Facebook
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
implementation 'com.facebook.android:facebook-android-sdk:5.15.1'
implementation 'com.google.android.gms:play-services-auth:18.0.0'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0
//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'
}
在此之后这是我的清单文件
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Geo_Activity"/>
<activity android:name=".Profile" />
<activity android:name=".HomeActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId"
tools:replace="android:value"
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>
</application>
现在的问题是,当我将 Facebuilder().build() 行添加到我的数组列表中时,应用程序崩溃了
解决方案
将您的依赖项更改为:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0' //1.0.2
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'
//Facebook
implementation 'com.facebook.android:facebook-android-sdk:5.15.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
//Cardview and Material
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.1.0' //1.1.0
//button
implementation 'info.hoang8f:fbutton:1.0.5'
implementation 'com.google.android.gms:play-services-location:17.0.0'
编辑 :
将这两个 strng 资源添加到您的 strngs :
<string name="facebook_application_id" translatable="false">APP_ID</string>
<!-- Facebook Application ID, prefixed by 'fb'. Enables Chrome Custom tabs. -->
<string name="facebook_login_protocol_scheme" translatable="false">fbAPP_ID</string>
如果您运行该应用程序,它现在可以工作,但是在您获得应用程序 ID 和方案之前,单击 facebook 按钮不会让用户获得身份验证
要获取应用 ID,请登录您的 Facebook 帐户,访问开发者页面https://developers.facebook.com/ 在此处创建一个应用,然后添加“facebook 登录”,然后按照给出的说明进行操作。您将在您的 Facebook 应用程序页面顶部找到您的应用程序 ID
只有两个注意事项:
您需要将“OAuth 重定向 URI”从 firebase 控制台页面(启用 facebook 身份验证时给出的链接)复制到您的 facebook 应用程序的设置
您将需要“密钥哈希”,您可以按照此处所述获取“密钥哈希” https://stackoverflow.com/a/25524657/9006761 然后将其复制到您的 Facebook 应用程序设置
编辑:方案只是以'fb'为前缀的应用程序ID
推荐阅读
- c# - 在 .net Core 中验证和发送 GraphQL 的自定义错误
- java - 如何通过键盘输入从 HashMap 中删除项目?
- mongodb - mongoDB聚合&分两个字段
- c++ - 仅更新 TFLITE 模型的最后一个分类层
- python - 在 Flask 中解析嵌套表单数组,支持在具有多个值的元素上使用 getlist()
- bots - 未收到回复时转到下一个问题
- python - 如何对 boto3 角色假设进行故障排除
- cgal - 如何使用 CGAL 在 2D alpha 形状后获得剩余的三角形?
- scala - 始终从 spark 的 s3 存储桶中读取最新文件夹
- javascript - 使用 CSS 类进行验证时,jQuery 验证器不适用于复选框列表