我得到com.google.android.gms.common.api.ApiException: 12500
,无法弄清楚。
此问题仅与Google登录名有关,它仍适用于创建的帐户。
我尝试过SHA1,SHA256,Google Play服务是最新的,尝试过不同的帐户,电话和模拟器。我也更新了json文件。
LoginActivity检查电子邮件和密码,然后检查服务器是否授权详细信息
public class LoginActivity extends AppCompatActivity{
private EditText userName, pass;
private FirebaseAuth mAuth;
Dialog settingsDialog;
private GoogleSignInClient mGoogleSignInClient;
private SignInButton signInButton;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.activity_login);
userName = (EditText) findViewById(R.id.login_username_text);
pass = (EditText) findViewById(R.id.login_password_text);
mAuth = FirebaseAuth.getInstance();
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
signInButton = (SignInButton) findViewById(R.id.google_signin_button);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 101);
}
});
}
public void loginButtonClicked(View view){
settingsDialog = new Dialog(this);
if(!userName.getText().toString().isEmpty() && !pass.getText().toString().isEmpty()) {
mAuth.signInWithEmailAndPassword(userName.getText().toString(), pass.getText().toString())
.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
FirebaseUser user = mAuth.getCurrentUser();
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout, null));
settingsDialog.show();
loginSucessfull(user);
} else {
//Handle invalid password or email
Toast toast = Toast.makeText(getApplicationContext(),R.string.invalid_name, Toast.LENGTH_SHORT);
toast.show();
}
}
});
}
}
private void loginSucessfull(FirebaseUser user){
Intent myIntent = new Intent(LoginActivity.this, TopicRoomActivity.class);
myIntent.putExtra("mauth", user);
LoginActivity.this.startActivity(myIntent);
finish();
}
public void createButtonClicked(View view){
Intent myIntent = new Intent(LoginActivity.this, CreateAccountActivity.class);
LoginActivity.this.startActivity(myIntent);
}
@Override
public void onStop(){
super.onStop();
if(settingsDialog != null)
settingsDialog.dismiss();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == 101) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
Log.w("*******","Google sign in failed", e);
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account){
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
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.w("******************","Logining in");
FirebaseUser user = mAuth.getCurrentUser();
loginSucessfull(user);
} else {
}
// ...
}
});
}
}
异常如下:
com.google.android.gms.common.api.ApiException:12500: 在com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(未知 资料来源:4) 在com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(未知 资料来源:8) 在com.juddit.juddit_main.LoginActivity.onActivityResult(LoginActivity.java:122) 在android.app.Activity.dispatchActivityResult(Activity.java:7454) 在android.app.ActivityThread.deliverResults(ActivityThread.java:4353) 在android.app.ActivityThread.handleSendResult(ActivityThread.java:4402) 在android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49) 在android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 在android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1808) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:193) 在android.app.ActivityThread.main(ActivityThread.java:6669) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:493) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)