我收到电话验证错误。我成功收到了 OTP,但在与 GitHub 的团队成员共享我的项目后,我收到了此错误。
我还在我的新 Firebase 控制台中添加了我的 SHA 1 和 SHA 256。我还添加了依赖项,但仍然出现此错误。
我还想通知,在将我的项目转移到 GitHub 后,我创建了新的 firebase 帐户并在该项目中添加了 SHA 1 和 SHA 256
Logcat:
03-16 16:19:40.001 8163-8163/com.roundtripride E/zzf: Problem retrieving SafetyNet Token: 7:
03-16 16:19:40.679 8163-8235/com.roundtripride E/FirebaseAuth: [GetAuthDomainTask] Error getting project config. Failed with INVALID_CERT_HASH 400
03-16 16:19:40.713 8163-8163/com.roundtripride E/zzf: Failed to get reCAPTCHA token with error [There was an error while trying to get your package certificate hash.]- calling backend without app verification
03-16 16:19:41.202 8163-8201/com.roundtripride E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17093 null
03-16 16:19:41.202 8163-8163/com.roundtripride E/Tag: onVerificationFailed : This request is missing a valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or check the logcat for more details.
03-16 16:19:41.202 8163-8163/com.roundtripride E/Tag: onVerificationFailed : This request is missing a valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or check the logcat for more details.
03-16 16:19:41.202 8163-8163/com.roundtripride E/Tag: onVerificationFailed : com.google.firebase.auth.FirebaseAuthException: This request is missing a valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or check the logcat for more details.
依赖:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'com.google.android.libraries.places:places:2.4.0'
implementation platform('com.google.firebase:firebase-bom:26.7.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth:20.0.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.intuit.sdp:sdp-android:1.0.6'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.amitshekhar.android:jackson-android-networking:1.0.2'
implementation 'com.github.prolificinteractive:material-calendarview:1.6.0'
implementation 'androidx.browser:browser:1.3.0'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
}
代码:
public class OTPVerifyActivity extends BaseActivity implements View.OnClickListener {
Context context;
private FirebaseAuth mAuth;
private String mVerificationId;
String idToken = "", mobile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_otp_verify);
Utility.setLoginStatusColor(this);
context = this;
txt_finish = findViewById(R.id.txt_finish);
edt_1 = findViewById(R.id.edt_1);
mAuth = FirebaseAuth.getInstance();
mobile = getIntent().getStringExtra("mobile");
sendVerificationCode();
txt_finish.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view == txt_finish) {
Utility.hideSoftKeyboard(edt_1, context);
if (edt_1.getText().toString().equals("")) {
Utility.errDialog("Please enter OTP", context);
} else {
verifyVerificationCode(edt_1.getText().toString().trim());
}
}
}
private void sendVerificationCode() {
PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber("+91" + mobile) // Phone number to verify
.setTimeout(30L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(this) // Activity (for callback binding)
.setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks
.build();
PhoneAuthProvider.verifyPhoneNumber(options);
}
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
Log.e("Tag", "get Data : " + phoneAuthCredential.getSmsCode());
Utility.dismissProgressDialog(pd);
String code = phoneAuthCredential.getSmsCode();
if (code != null) {
edt_1.setText(code);
verifyVerificationCode(code);
}
}
@Override
public void onVerificationFailed(FirebaseException e) {
Utility.dismissProgressDialog(pd);
Log.e("Tag", "onVerificationFailed : " + e.getMessage());
Log.e("Tag", "onVerificationFailed : " + e.getLocalizedMessage());
Log.e("Tag", "onVerificationFailed : " + e.toString());
Utility.errDialog(e.getMessage(), context);
}
@Override
public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
mVerificationId = s;
Utility.dismissProgressDialog(pd);
}
};
private void verifyVerificationCode(String code) {
//Log.e("Tag","Verify code : "+code);
pd = Utility.showProgressDialog(context);
try {
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, code);
signInWithPhoneAuthCredential(credential);
} catch (Exception e) {
Log.e("Tag", "PhoneAuthCredential Exception " + e.getMessage());
}
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(OTPVerifyActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
user.getIdToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
idToken = task.getResult().getToken();
Utility.dismissProgressDialog(pd);
Log.e("Tag", "Success OTP " + isDriver);
MyPreference.setPreferenceValue(context,"isLogin","true");
}
}
});
} else {
Utility.dismissProgressDialog(pd);
//verification unsuccessful.. display an error message
String message = "Something is wrong, we will fix it soon...";
if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
message = "Invalid code entered...";
}
Log.e("Tag", message);
Utility.errDialog(message, context);
}
}
});
}
}
答案 0 :(得分:1)
从您的旧 Firebase 帐户中删除您的调试 SHA-1 和 SHA-256。
打开android studio并点击右上角的gradle>点击你的项目>选择应用>选择任务>选择android>点击签名报告>从那里复制我们的SHA1和SHA-256。
在您的新 Firebase 帐户中添加 SHA1 和 SHA-256。(如果您要从 2 个系统构建 apk,请同时添加系统的 SHA1 和 SHA-256)。
您需要确保在 Firebase 控制台中启用了电话身份验证 => 身份验证 => 登录方法。
在 build.gradle(:app) 中添加依赖
实现'androidx.browser:browser:1.3.0'
转到谷歌云控制台,选择您的项目。
点击导航菜单并选择 API 和服务,然后选择仪表板。
点击启用api和服务并启用api“Android设备验证”。
下载并替换项目中最新的 google-services.json 文件。
答案 1 :(得分:0)
实现'androidx.browser:browser:1.3.0'
请添加此依赖项,然后再检查一次 sha1 和 sha256,然后尝试