在我的应用程序中通过Google登录会出现此错误:
发生了内部错误。 [OPERATION_NOT_ALLOWED]
我在Firebase控制台中启用了Google。权限是正确的,我似乎无法找到问题。我确定这与我的代码无关,但如果确实告诉我。
SignInactivity:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
}
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// An unresolvable error has occurred and Google APIs (including Sign-In) will not
// be available.
Log.d(TAG, "onConnectionFailed:" + connectionResult);
Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed
Log.e(TAG, "Google Sign In failed.");
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mFirebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
if (!task.isSuccessful()) {
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(SignInActivity.this, "Authentication failed: " + task.getException(),
Toast.LENGTH_SHORT).show();
} else {
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
}
}
);
}
答案 0 :(得分:34)
我遇到了同样的问题。我在论坛帖子 [Google Auth] com.google.firebase.FirebaseException: An internal error has occurred 中找到了解决方案。
当我在控制台Firebase中未启用身份验证方法时,发生了这种情况。当我启用Google身份验证时,我得到了相同的异常,只是没有[OPERATION_NOT_ALLOWED]。
答案 1 :(得分:11)
比它工作正常:)
答案 2 :(得分:1)
如果您使用电子邮件和密码注册,请按照以下步骤操作。
Go to https://console.firebase.google.com/
Select your project.
Click on Authentication from menu option(Right-side menu)
Click on SIGN-IN-METHOD
Click on Email/Password and enable it.
Click on SAVE.
答案 3 :(得分:0)
启用您要使用的firebase console上的SIGN-IN-METHOD方法或您在APP中使用的方法。
答案 4 :(得分:0)
最后我找到了适合我的解决方案。事实是,即使您已成功设置电子邮件+密码验证方法,您也需要创建一个移动应用程序(在我的情况下)并将其与您的项目相关联。之后,FireBase将按预期工作。
答案 5 :(得分:0)
转到Google&#34; https://console.developers.google.com/apis/library/&#34;到您的项目并启用Identity Toolkit API
答案 6 :(得分:0)
运行项目时出现“发生内部错误”。请确保您的模拟器可以连接互联网。在我的情况下,我的模拟器没有连接到互联网。为此,请按照以下步骤操作。(对于Windows PC)
然后在模拟器中,关闭WiFi,然后再次打开。对我有用。