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

标签 android firebase firebase-authentication

我不知道这个错误是什么意思。我在 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/

相关文章:

java - 等待 onPostExecute 完成以制作新的适配器

android - 在 Canvas 上垂直绘制文本

javascript - 如何修复 Node 中未定义错误的 "Cannot read property ' trim'

ios - 在用户使用 Firebase Auth 和 Swift 验证了他们的电子邮件后,我如何重定向回我的应用程序?

Android - 启动新的 Activity (java.lang.NullPointerException)

android - 无法发现 BLE 设备

android - 为flutter项目添加Firebase无法正常工作

Swift:如何为从 Firebase 数据库获取数据的函数实现完成处理程序

android - 不同的权限 Firebase Auth

firebase - 将 drupal 用户迁移到 firebase auth