我正在尝试使用Firebase身份验证登录,但出现FirebaseException。在我的活动中,我具有onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(R.string.title_calendar);
initData();
}
onStart方法:
@Override
protected void onStart() {
super.onStart();
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
// something
} else {
signIn();
}
}
和signIn方法:
private void signIn() {
mAuth.signInWithEmailAndPassword("test@abc.com", "123456789").addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
Log.i("Log", "signIn:SUCCESS");
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("Log", "signIn:FAILURE", exception);
}
});
}
我得到这个:
E/shinseiLog: signIn:FAILURE
com.google.firebase.FirebaseException: An internal error has occurred. [ Identity Toolkit API has not been used in project 611854850952 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/identitytoolkit.googleapis.com/overview?project=611854850952 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. ]
at com.google.android.gms.internal.jz.zzK(Unknown Source:147)
at com.google.android.gms.internal.jb.zza(Unknown Source:12)
at com.google.android.gms.internal.kj.zzL(Unknown Source:11)
at com.google.android.gms.internal.kl.onFailure(Unknown Source:35)
at com.google.android.gms.internal.kb.onTransact(Unknown Source:79)
at android.os.Binder.execTransact(Binder.java:697)
在firebase控制台以及Identity Toolkit API上启用了身份验证方法电子邮件,密码。
答案 0 :(得分:0)
请使用以下URL检查您的项目现有的Firebase控制台 https://console.firebase.google.com 如果可用,请使用重建项目 生成->重建项目 并使用Gradle文件重新同步项目
答案 1 :(得分:0)
Firebase中的google-services.json文件是否最新?在Firebase中启用服务时,JSON会更新。尝试从Firebase重新下载它,然后检查它是否不同?