Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android上使用firebase phone auth api进行身份验证时,SMS验证码请求失败,状态代码未知17006_Android_Firebase_Firebase Authentication - Fatal编程技术网

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

在android上使用firebase phone auth api进行身份验证时,SMS验证码请求失败,状态代码未知17006,android,firebase,firebase-authentication,Android,Firebase,Firebase Authentication,我不知道这个错误是什么意思。我在谷歌上搜索了很多,但找不到为什么会出现这个错误 E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17006 null 我正在试着,并且试着核实他们的电话号码。没有发送代码,也没有调用回调函数。我不知道这里有什么问题 以下活动用于从edittext获取电话号码,并发送该电话号码上的验证码,然后开始下一个活动,用户将在其中输

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

E/FirebaseAuth: [SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17006 null
我正在试着,并且试着核实他们的电话号码。没有发送代码,也没有调用回调函数。我不知道这里有什么问题

以下活动用于从edittext获取电话号码,并发送该电话号码上的验证码,然后开始下一个活动,用户将在其中输入他们获得的代码:

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();
        }
    };
}
以下是验证用户从上一个(以上)活动中获得的验证代码的活动:

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();
                        }
                    });
        });
    }
}

我想您可能忘了在firebase控制台中启用电话登录方法


尝试将电话添加为登录提供商,然后重试。

确保设备已连接到internet。
同样在Google云控制台中,为您的项目启用。通过这种方式,firebase SDK可以验证设备以继续进行身份验证。

当您重复使用特定的电话号码,为了测试而登录和注销,而不将其添加到“用于测试的电话号码”中时,Google可能最终会暂时阻止它,并出现一个错误,表明检测到异常行为,或者出现以下错误:“SMS验证码请求失败:未知状态码:17010 null”。

我也遇到同样的问题,启用此选项后问题得到解决