gpt4 book ai didi

Android Firebase 电话身份验证 INVALID_APP_CREDENTIAL :App validation failed

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:54:18 26 4
gpt4 key购买 nike

我是 android firebase 的新手,我已经为 Firebase Auth 实现了必要的库。我尝试输入一个有效数字,但日志显示:

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)

这是我的代码:

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
}

}

请告诉我有什么问题谢谢..

最佳答案

添加SHA Certificate Fingerprint解决了我的问题。好吧,我对此还很陌生,但我设法显示了输出,并且能够收到短信验证。

我的代码供引用: https://github.com/coozgan/TestingPhoneAuth

关于Android Firebase 电话身份验证 INVALID_APP_CREDENTIAL :App validation failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44432204/

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