这是我的第一次尝试。...试图找到最近2天的问题。我正在尝试将google登录集成到android应用中,但如下所示:com.google.android.gms.common.api.ApiException:12500
遵循以下代码:https: //firebase.google.com/docs/auth/android/google-signin
确保在开发人员控制台中存在oauth客户端ID,并具有〜/ .android / debug.keystore中正确的SHA-1指纹,如其他文章中所建议。
在应用程序级别上使用最新的Play服务49和build.gradle:实施'com.google.android.gms:play-services-auth:16.0.1'
在项目级别的build.gradle中使用以下代码:
public class SignUpActivity extends AppCompatActivity {
private GoogleSignInClient gsc;
private FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(String.valueOf(R.string.gplus_api_client_id))
.requestEmail()
.build();
gsc = GoogleSignIn.getClient(this, gso);
//Initialize firebase authentication
firebaseAuth = FirebaseAuth.getInstance();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task < GoogleSignInAccount > task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task < GoogleSignInAccount > completedTask) {
try {
//Sign in Successful
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
Log.w("SignUpActivity/handleSignInResult", "Trying signing in with Google... " + account);
firebaseAuthWithGoogle(account);
// Signed in successfully, show authenticated UI.
// Log.w("SignUpActivity/handleSignInResult", "Google sign in successful for account " + account);
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("SignUpActivity/handleSignInResult", "Google sign in failed with exception: " + e);
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account) {
Log.i("SignUpActivity/firebaseAuthWithGoogle", "Signed in as : " + account.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
FirebaseUser user = firebaseAuth.getCurrentUser();
Log.i("SignUpActivity/firebaseAuthWithGoogle", "Sign in successful for user : " + user);
} else {
Log.e("SignUpActivity/firebaseAuthWithGoogle", "User Authentication failed.");
Snackbar.make(findViewById(R.id.view_signup), "Authentication failed.", Snackbar.LENGTH_SHORT);
}
}
});
}
}Run Code Online (Sandbox Code Playgroud)
azw*_*bar 10
我有这个问题。并且已经解决了。SHA1调试和发布都已添加到Firebase控制台,但仍然无法正常工作。另外,我尝试仅将SHA1调试,但仍然无法正常工作。经过无数次尝试和错误后,我通过从凭据菜单中填写“ oAuth同意屏幕”信息来解决了问题,这是以下步骤: