Android Firebase手机身份验证INVALID_APP_CREDENTIAL:应用验证失败 [英] Android Firebase phone authentication INVALID_APP_CREDENTIAL:App validation failed
本文介绍了Android Firebase手机身份验证INVALID_APP_CREDENTIAL:应用验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
W / JEJE:onVerificationFailed
com.google。 firebase.FirebaseException:发生内部错误。 [INVALID_APP_CREDENTIAL:应用验证失败]
在com.google.android.gms.internal.nf.zzK(未知来源)
在com.google.android.gms.internal.og.zza(未知来源)
在com.google.android.gms.internal.oh.run(未知来源)
在android.os.Handler.handleCallback(Handler.java:751)
在android.os .Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android .internal.os.ZygoteInit.main(ZygoteInit.java:778)
这是我的代码:
public class MainActivity extends AppCompatActivity {
private static String mVerificationId;
private static PhoneAuthProvider.ForceResendingToken mResendToken;
private static FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText =(EditText)findViewById(R.id.phone);
Button submit =(Button)findViewById(R.id.submit);
PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks(){
@Override $ b $ public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential){
Log.d(JEJE ,onVerificationCompleted:+ phoneAuthCredential);
signInWithPhoneAuthCredential(phoneAuthCredential); b
$ b @Override
public void onVerificationFailed(FirebaseException e){
Log.w(JEJE,onVerificationFailed,e);
if(e instanceof FirebaseAuthInvalidCredentialsException){
Log.d(JEJE,INVALID REQUEST);
} else if(e instanceof FirebaseTooManyRequestsException){
Log.d(JEJE,Too many Request);
$ b @Override
public void onCodeSent(String s,PhoneAuthProvider.ForceResendingToken forceResendingToken){
super.onCodeSent(s,forceResendingToken);
Log.d(JEJE,onCodeSent:+ s);
mVerificationId = s;
mResendToken = forceResendingToken;
}
};
submit.setOnClickListener(new View.OnClickListener(){
@Override $ b $ public void onClick(View v){
String phoneNum = editText.getText()。 toString();
Toast.makeText(MainActivity.this,phoneNum,Toast.LENGTH_SHORT).show();
verifyPhone(phoneNum,mCallBacks);
}
});
private void signInWithPhoneAuthCredential(PhoneAuthCredential phoneAuthCredential){
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener< AuthResult>(){
@Override
public void onComplete(@NonNull Task< AuthResult> task){
if(task.isSuccessful()){
FirebaseUser user = task.getResult()。getUser();
} else {
if(task.getException()instanceof FirebaseAuthInvalidCredentialsException){
//输入的验证码无效
}
}
}
}) ;
$ b public void verifyPhone(String phoneNumber,PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks){
PhoneAuthProvider.getInstance()。verifyPhoneNumber(
+639952874699,// Phone数字来验证
60,//超时持续时间
TimeUnit.SECONDS,//超时单位
this,// Activity(用于回调绑定)
mCallbacks); // OnVerificationStateChangedCallback
}
}
请告诉我什么错误的感谢..
解决方案
添加 SHA证书指纹解决了我的问题。那么,我相当新,但我设法显示输出,我能够收到短信验证。
这里是我的代码:
< a href =https://github.com/coozgan/TestingPhoneAuth =noreferrer> https://github.com/coozgan/TestingPhoneAuth
I am really new to android firebase and I have implemented the necessary libraries for Firebase Auth. I try putting a valid number, but the log says its:
W/JEJE: onVerificationFailed
com.google.firebase.FirebaseException: An internal error has occurred. [ INVALID_APP_CREDENTIAL:App validation failed ]
at com.google.android.gms.internal.nf.zzK(Unknown Source)
at com.google.android.gms.internal.og.zza(Unknown Source)
at com.google.android.gms.internal.oh.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Here is my code:
public class MainActivity extends AppCompatActivity {
private static String mVerificationId;
private static PhoneAuthProvider.ForceResendingToken mResendToken;
private static FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText) findViewById(R.id.phone);
Button submit = (Button) findViewById(R.id.submit);
final PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Log.d("JEJE", "onVerificationCompleted:" + phoneAuthCredential);
signInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(FirebaseException e) {
Log.w("JEJE", "onVerificationFailed", e);
if (e instanceof FirebaseAuthInvalidCredentialsException) {
Log.d("JEJE", "INVALID REQUEST");
} else if (e instanceof FirebaseTooManyRequestsException) {
Log.d("JEJE", "Too many Request");
}
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
Log.d("JEJE", "onCodeSent:" + s);
mVerificationId = s;
mResendToken = forceResendingToken;
}
};
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNum = editText.getText().toString();
Toast.makeText(MainActivity.this, phoneNum, Toast.LENGTH_SHORT).show();
verifyPhone(phoneNum,mCallBacks);
}
});
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential phoneAuthCredential) {
mAuth.signInWithCredential(phoneAuthCredential).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
FirebaseUser user = task.getResult().getUser();
}else {
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
// The verification code entered was invalid
}
}
}
});
}
public void verifyPhone(String phoneNumber, PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks){
PhoneAuthProvider.getInstance().verifyPhoneNumber(
"+639952874699", // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
this, // Activity (for callback binding)
mCallbacks); // OnVerificationStateChangedCallback
}
}
please tell me whats wrong thanks..
解决方案
Adding SHA Certificate Fingerprint solves my problem. Well, Im fairly new to this but I managed to show output and I was able to received a sms verification.
For reference here are my codes: https://github.com/coozgan/TestingPhoneAuth
这篇关于Android Firebase手机身份验证INVALID_APP_CREDENTIAL:应用验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文