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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加