gpt4 book ai didi

android - 升级后 Firebase Auth UI 出现 Google 登录错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:21 27 4
gpt4 key购买 nike

我成功地使用了旧版本的 firebase auth ui,但在升级到最新版本后,我在尝试使用 Google 登录时收到以下错误:

E/AuthUI: A sign-in error occurred.
com.firebase.ui.auth.FirebaseUiException: Code: 10, message: 10:
at com.firebase.ui.auth.data.remote.GoogleSignInHandler.onActivityResult(GoogleSignInHandler.java:106)
at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onActivityResult(AuthMethodPickerActivity.java:225)
at android.app.Activity.dispatchActivityResult(Activity.java:7235)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4320)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Facebook 和电子邮件登录没问题。

我在我的应用程序 gradle 中使用这些依赖项:

implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.facebook.android:facebook-login:4.32.0'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'

以及我的项目级 gradle 中的以下内容:

classpath 'com.google.gms:google-services:4.0.1'

登录 Activity :

public class ActivityLoginView extends ActivityBase {

// Misc
public static final int RC_SIGN_IN = 100;
public static final String TAG = "ActivityLoginView";

public ActivityLoginViewModel activityLoginViewModel;

private static final String PRIVACY_POLICY_URL = "https://www.editedout.com/pages/privacy";

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

activityLoginViewModel = new ActivityLoginViewModel(this);

if (!activityLoginViewModel.isGooglePlayServicesAvailable()) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("No Google Play Services");
alertDialog.setMessage("This app requires Google Play Services to be installed and enabled");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
System.exit(0);
}
});
alertDialog.show();

} else {

FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
// See if user is logged in already
if (currentUser != null) {

// User already signed in
if (!BuildConfig.DEBUG) {
Crashlytics.setUserIdentifier(currentUser.getUid());
Crashlytics.setUserName(currentUser.getDisplayName());
Crashlytics.setUserEmail(currentUser.getEmail());
}

activityLoginViewModel.saveUserToFirebase();

} else {

startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder()
.setTheme(R.style.LoginTheme)
.setLogo(R.drawable.loginlogo)
.setAvailableProviders(getSelectedProviders())
.setPrivacyPolicyUrl(PRIVACY_POLICY_URL)
.setIsSmartLockEnabled(!BuildConfig.DEBUG)
.build(),
RC_SIGN_IN);

}
}
}

public void startMain() {

if (SPManager.getBoolean(this, SPManager.kOnBoardShown)) {

Intent intent = new Intent(this, ActivityHomePage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();

} else {

startActivity(ActivityOnBoard.newIntent(this));

}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SIGN_IN) {

handleSignInResponse(resultCode, data);

}
}

private void handleSignInResponse(int resultCode, Intent data) {
IdpResponse response = IdpResponse.fromResultIntent(data);

// Successfully signed in
if (resultCode == RESULT_OK) {

activityLoginViewModel.saveUserToFirebase();

} else {
// Sign in failed
if (response == null) {
// User pressed back button
showSnackbar(R.string.sign_in_cancelled);
return;
}

if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) {
showSnackbar(R.string.no_internet_connection);
return;
}

showSnackbar(R.string.unknown_error);
Log.e(TAG, "Sign-in error: ", response.getError());
}
}

private List<AuthUI.IdpConfig> getSelectedProviders() {

List<AuthUI.IdpConfig> selectedProviders = new ArrayList<>();

selectedProviders.add(new AuthUI.IdpConfig.GoogleBuilder()
.build());

selectedProviders.add(new AuthUI.IdpConfig.FacebookBuilder()
.build());

selectedProviders.add(new AuthUI.IdpConfig.EmailBuilder()
.setRequireName(true)
.setAllowNewAccounts(true)
.build());

//selectedProviders
// .add(new AuthUI.IdpConfig.PhoneBuilder().build());

return selectedProviders;

}

public void showSnackbar(@StringRes int errorMessageRes) {

View parentLayout = findViewById(android.R.id.content);
Snackbar.make(parentLayout, errorMessageRes, Snackbar.LENGTH_LONG).show();

}

@Override
public void onBackPressed() {

finishAffinity();

}

最佳答案

已修复。我忘记将我的新调试 SHA1 添加到 Firebase。

关于android - 升级后 Firebase Auth UI 出现 Google 登录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50598889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com