gpt4 book ai didi

android - 短信验证码请求失败,未知状态码 17006,同时在 android 上使用 firebase phone-auth api 进行身份验证

转载 作者:行者123 更新时间:2023-12-04 14:39:26 35 4
gpt4 key购买 nike

我不知道这个错误是什么意思。我在 Google 上搜索了很多,但找不到为什么会出现此错误。

E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17006 null
我正在尝试 authenticate android client with firebase phone auth sign-in method ,并尝试通过 sending a verification code on their phone 验证他们的电话号码.没有发送代码,也没有调用回调函数。我不知道这里有什么问题
这是从 edittext 获取电话号码并在该电话号码上发送验证码并开始下一个 Activity 的 Activity ,用户将在其中输入他们获得的代码:
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import com.google.firebase.FirebaseException;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;

import java.util.concurrent.TimeUnit;

public class PhoneOtpAuth extends AppCompatActivity {

private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_otp_auth);

EditText phoneNumberEditText = findViewById(R.id.phone_number);
Button signIn = findViewById(R.id.sign_in_button);

mAuth = FirebaseAuth.getInstance();

signIn.setOnClickListener(v -> {
String phoneNumber = phoneNumberEditText.getText().toString();

PhoneAuthOptions options =
PhoneAuthOptions.newBuilder(mAuth)
.setPhoneNumber(phoneNumber)
.setTimeout(60L, TimeUnit.SECONDS)
.setActivity(PhoneOtpAuth.this)
.setCallbacks(callbacks)
.build();

PhoneAuthProvider.verifyPhoneNumber(options);
});
}

PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
Intent signUpIntent = new Intent(PhoneOtpAuth.this, DriverSignup.class);
startActivity(signUpIntent);
finish();
}

@Override
public void onVerificationFailed(@NonNull FirebaseException e) {

}

@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
Intent otpVerificationIntent = new Intent(PhoneOtpAuth.this, OtpVerificationActivity.class);
otpVerificationIntent.putExtra("VerificationId", s);
startActivity(otpVerificationIntent);
finish();
}
};
}
这是验证用户从上一个(以上) Activity 中获得的验证码的 Activity :
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthOptions;
import com.google.firebase.auth.PhoneAuthProvider;

import java.util.concurrent.TimeUnit;

public class OtpVerificationActivity extends AppCompatActivity {

private String otp;

private FirebaseAuth mAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_otp_verification);

EditText otpEditText = findViewById(R.id.otp);
Button verifyOtp = findViewById(R.id.verify_otp_button);

mAuth = FirebaseAuth.getInstance();

otp = otpEditText.getText().toString();
String verificationId = getIntent().getExtras().getString("VerificationId");
FirebaseAuth mAuth = getIntent().getExtras().getParcelable("mAuth");

verifyOtp.setOnClickListener(v -> {
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, otp);

mAuth.signInWithCredential(phoneAuthCredential)
.addOnCompleteListener(task -> {
if(task.isSuccessful()) {
Intent signUpIntent = new Intent(OtpVerificationActivity.this, DriverSignup.class);
startActivity(signUpIntent);
finish();
}
});
});
}
}

最佳答案

当您重复使用特定的电话号码,为了测试而登录和退出时,没有将其添加到“用于测试的电话号码”中,Google 最终可能会暂时阻止它,并显示错误指示已检测到异常行为,或者出现错误: “短信验证码请求失败:未知状态码:17010 null”。

关于android - 短信验证码请求失败,未知状态码 17006,同时在 android 上使用 firebase phone-auth api 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66015192/

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