发生内部错误。 [MISSING_CLIENT_IDENTIFIER]

时间:2018-06-21 12:26:40

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

我正在使用电话身份验证,它工作正常,但是在登录注销几次后尝试显示此错误。发生内部错误。 [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);
        }
    }

}

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

尝试更新应用程序大类,例如:

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
}

答案 2 :(得分:0)

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

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'
相关问题