【问题标题】:An internal error has occurred. [ MISSING_CLIENT_IDENTIFIER ]发生内部错误。 [ MISSING_CLIENT_IDENTIFIER ]
【发布时间】:2018-11-30 18:54:39
【问题描述】:

我正在使用电话身份验证,它工作正常,但在几次登录注销尝试后,它显示此错误发生内部错误。 [ MISSING_CLIENT_IDENTIFIER ] 并没有收到验证码。我已插入所有 gradle 文件 google json 文件,并在 firebase 控制台中启用了身份验证。一开始还可以,但现在显示奇怪的错误,我现在只能输入白名单号码

我的 build.gradle 文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url "https://maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.devlearn.sohel.tkash"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:animated-vector-drawable:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.github.ybq:Android-SpinKit:1.1.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:gridlayout-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.firebaseui:firebase-ui-database:4.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.budiyev.android:circular-progress-bar:1.2.0'
    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'com.github.d-max:spots-dialog:0.7@aar'
    implementation 'com.github.HotBitmapGG:RingProgressBar:V1.2.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

我的登录密码:

package com.devlearn.sohel.tkash;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.devlearn.sohel.tkash.Models.UserDetails;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseException;
import com.google.firebase.FirebaseTooManyRequestsException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.concurrent.TimeUnit;

import dmax.dialog.SpotsDialog;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

public class LoginActivity extends AppCompatActivity {
    private EditText edtPhone;
    private EditText edtName;
    private TextView txtMessege;
    private RelativeLayout rootlayout;
    private ProgressBar progressBar;
    private Button btnLogin;

    private FirebaseAuth mAuth;
    private DatabaseReference mDatabaseUsers;

    public String phoneNumber;
    public String userName;
    private String mVerificationId;
    public SpotsDialog waitingDialog;
    private PhoneAuthProvider.ForceResendingToken mResendToken;

    private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks;

//    ctrl+o
    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.SplashThme);
        //before setcontentview
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/Ubuntu.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build());
        setContentView(R.layout.activity_login);


        edtPhone = (EditText)findViewById(R.id.edtphone);
        edtName = findViewById(R.id.edtName);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        txtMessege = (TextView)findViewById(R.id.txtMessege);
        rootlayout = (RelativeLayout)findViewById(R.id.rootlayout);

        mAuth = FirebaseAuth.getInstance();
        mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users");

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                startActivity(new Intent(LoginActivity.this,MainActivity.class));
                phoneNumber = edtPhone.getText().toString();
                userName = edtName.getText().toString().trim();

                if(TextUtils.isEmpty(phoneNumber))
                {
                    edtPhone.setError("Incorrect phone number format");
                    requestFocus(edtPhone);
                }
                else if(TextUtils.isEmpty(userName))
                {
                    edtName.setError("Please insert your name");
                    requestFocus(edtName);
                }
                else
                {
                    phoneNumber = edtPhone.getText().toString();

                    mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
                        @Override
                        public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential) {
                            signInWithPhoneAuthCredential(phoneAuthCredential);
                        }

                        @Override
                        public void onVerificationFailed(FirebaseException e) {
                            String error = e.getMessage();
                            Snackbar.make(rootlayout, "Error "+e, Snackbar.LENGTH_LONG)
                                    .show();
                            Log.d("Error fire",error);
                            if (e instanceof FirebaseAuthInvalidCredentialsException) {
                                // Invalid request
                                // ...
                                String erro = e.getMessage();
                                Toast.makeText(LoginActivity.this, "error"+ erro, Toast.LENGTH_SHORT).show();
                                Log.d("Error fire",erro);
                            } else if (e instanceof FirebaseTooManyRequestsException) {
                                // The SMS quota for the project has been exceeded
                                // ...
                                String err = e.getMessage();
                                Toast.makeText(LoginActivity.this, "error"+ err, Toast.LENGTH_SHORT).show();
                                Log.d("Error fire",err);
                            }
                        }

                        @Override
                        public void onCodeSent(String verificationId,
                                               PhoneAuthProvider.ForceResendingToken token) {
                            // The SMS verification code has been sent to the provided phone number, we
                            // now need to ask the user to enter the code and then construct a credential
                            // by combining the code with a verification ID.
                            // Save verification ID and resending token so we can use them later
                            mVerificationId = verificationId;
                            mResendToken = token;

//                progressBar.setVisibility(View.INVISIBLE);

                            // ...
                        }
                    };
                    PhoneAuthProvider.getInstance().verifyPhoneNumber(
                            phoneNumber,
                            60,
                            TimeUnit.SECONDS,
                            LoginActivity.this,
                            mCallbacks
                    );

                    LoginUisngPhone();

                }
            }
        });
    }

    private void LoginUisngPhone() {

        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("Verification");
//        dialog.setMessage("Please provide verification Code");

        LayoutInflater inflater = LayoutInflater.from(this);
        View layout_verification = inflater.inflate(R.layout.layout_verification,null);

        final EditText edtVerificationCode = layout_verification.findViewById(R.id.edtVerificationCode);
        final TextView txtCountdown = layout_verification.findViewById(R.id.txtCountdown);
        final ProgressBar progressBar = layout_verification.findViewById(R.id.progressbar);

        CountDownTimer countDownTimer = new CountDownTimer(60000, 1000) {

            public void onTick(long millisUntilFinished) {
                txtCountdown.setText("Please provide Verificatin Code sec remaining: " + millisUntilFinished / 1000);
                txtMessege.setTextColor(getResources().getColor(R.color.errorcolor));
                txtMessege.setText("Please wait for "+ millisUntilFinished / 1000+" sec to try Again");
                btnLogin.setEnabled(false);
                edtName.setEnabled(false);
                edtPhone.setEnabled(false);

            }

            public void onFinish() {
                txtCountdown.setText("Please Try Again!");
                txtMessege.setText("A verification Code will be sent when you click send verification");
                btnLogin.setEnabled(true);
                edtName.setEnabled(true);
                edtPhone.setEnabled(true);
            }
        }.start();

        dialog.setView(layout_verification);

        dialog.setPositiveButton("SIGN IN", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
//                dialog.dismiss();

                //disable sign in button while processing
//                btnLogin.setEnabled(false);

                //validate the data
                if (TextUtils.isEmpty(edtVerificationCode.getText().toString())) {
//                    edtVerificationCode.setError("Enter verification Code");
//                    requestFocus(layout_verification.findViewById(R.id.edtVerificationCode));
                    Toast.makeText(LoginActivity.this, "Insert Code", Toast.LENGTH_SHORT).show();

                }
                else
                {
                    String verificationCode = edtVerificationCode.getText().toString();

                    PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, verificationCode);
                    //dot waitng process
//                    waitingDialog = new SpotsDialog(LoginActivity.this);
//                    waitingDialog.show();

                    signInWithPhoneAuthCredential(credential);
//                    waitingDialog.dismiss();
                }



            }
        });
        dialog.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
        mAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {
                            // Sign in success, update UI with the signed-in user's information
//                            Log.d(TAG, "signInWithCredential:success");
                            //dot waitng process
//                            waitingDialog.dismiss();
                            Toast.makeText(LoginActivity.this, "Success! checking user exists or not", Toast.LENGTH_SHORT).show();
                            checkUserExists();
                            // ...
                        } else {
                            // Sign in failed, display a message and update the UI
                            if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                // The verification code entered was invalid
                                String error = task.getException().getMessage();
                                Snackbar.make(rootlayout, "Invalid " + error, Snackbar.LENGTH_LONG)
                                        .show();
                                Log.d("Error fire2",error);

                            }
                        }
                    }
                });
    }

    private void checkUserExists() {
        if(mAuth.getCurrentUser()!=null)
        {
            final String user_id = mAuth.getCurrentUser().getUid();

            mDatabaseUsers.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if(dataSnapshot.hasChild(user_id))
                    {
                        Toast.makeText(LoginActivity.this, "Welcome!!", Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                        finish();
                    }
                    else
                    {
//                        Intent intent = new Intent(LoginActivity.this,AccountSetupActivity.class);
//                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//                        startActivity(intent);
                        mDatabaseUsers.child(user_id).child("userName").setValue(userName);
                        mDatabaseUsers.child(user_id).child("userPhone").setValue(phoneNumber);
                        mDatabaseUsers.child(user_id).child("currentBalance").setValue(0.0);
                        mDatabaseUsers.child(user_id).child("totalBalance").setValue(0.0);
                        Toast.makeText(LoginActivity.this, "Success!!", Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                        finish();

                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {



                }
            });

        }
    }

    private void requestFocus(View view) {
        if (view.requestFocus()) {
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        }
    }

}

【问题讨论】:

  • @ParaskevasNtsounos 我刚刚更新了实现,但仍然收到相同的错误 [缺少客户端标识符]
  • 也更新 google-services 类路径,尝试复制粘贴我的代码,然后重建您的项目并运行应该可以工作

标签: android firebase gradle android-gradle-plugin firebase-authentication


【解决方案1】:

最后我解决了这个问题,这是因为我尝试和测试了多次使用我的 wifi 网络和移动网络的同一设备。因此,他们以某种方式阻止了对该客户端 ID 的请求。一旦我在具有不同网络的不同设备上尝试它,一切都很好。 谢谢大家

【讨论】:

    【解决方案2】:

    要解决这个问题,请更改以下代码行:

    classpath 'com.google.gms:google-services:4.0.0'
    

    classpath 'com.google.gms:google-services:4.0.1'
    

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
    implementation 'com.firebaseui:firebase-ui-database:3.3.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    

    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'
    implementation 'com.firebaseui:firebase-ui-database:4.0.0'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    

    【讨论】:

    • 再次下载json文件,放到你的项目中。我还能看到更改后的代码吗?
    • 是的,我重新下载了 json 文件,但是当我尝试登录时出现内部错误。 [ MISSING_CLIENT_IDENTIFIER ] 还更新了我上面的代码
    • 请确保您已在 Firebase 控制台中启用 Phone authentication。是不是启用对了?请启用它!
    • 我正在使用电话身份验证,为什么我不启用它?如果它禁用错误消息是不同的。
    • 您是否尝试过从头开始创建一个新项目?
    【解决方案3】:

    尝试像这样更新应用程序:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId "com.devlearn.sohel.tkash"
            minSdkVersion 21
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:design:27.1.1'
        implementation 'com.android.support:animated-vector-drawable:27.1.1'
        implementation 'com.android.support:customtabs:27.1.1'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        implementation 'com.github.ybq:Android-SpinKit:1.1.0'
        implementation 'com.google.firebase:firebase-core:16.0.1'
        implementation 'com.google.android.gms:play-services-ads:15.0.1'
        implementation 'com.android.support:recyclerview-v7:27.1.1'
        implementation 'com.android.support:cardview-v7:27.1.1'
        implementation 'com.android.support:gridlayout-v7:27.1.1'
        implementation 'com.google.android.gms:play-services-auth:15.0.1'
        implementation 'com.google.firebase:firebase-database:16.0.1'
        implementation 'com.google.firebase:firebase-storage:16.0.1'
        implementation 'com.firebaseui:firebase-ui-database:3.3.1'
        implementation 'com.google.firebase:firebase-auth:16.0.2'
        implementation 'com.budiyev.android:circular-progress-bar:1.2.0'
        implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
        implementation 'com.github.d-max:spots-dialog:0.7@aar'
        implementation 'com.github.HotBitmapGG:RingProgressBar:V1.2.3'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    }
    apply plugin: 'com.google.gms.google-services'
    

    还有像这样的项目:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
            classpath 'com.google.gms:google-services:4.0.1'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            maven { url "https://jitpack.io" }
            maven {
                url "https://maven.google.com"
            }
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    【讨论】:

    • @Sohel Mahmud 这对你有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    相关资源
    最近更新 更多