gpt4 book ai didi

android - com.google.android.gms.common.api.ApiException : 10:

转载 作者:行者123 更新时间:2023-12-05 07:34:44 29 4
gpt4 key购买 nike

我想使用下面的 gradle 进行 Google SignIn。

implementation 'com.google.android.gms:play-services-auth:15.0.0'

初始化代码如下:

private fun initGooglePlus() {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.server_client_id))
.requestEmail()
.build()
mGoogleSignInClient = GoogleSignIn.getClient(this.activity!!, gso)
}

我在点击按钮时调用了下面的代码

private fun googlePlusLogin() {
val signInIntent = mGoogleSignInClient!!.signInIntent
startActivityForResult(signInIntent, SIGN_IN_CODE)
}

OnActivityForResult

override
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == SIGN_IN_CODE) {
val task = GoogleSignIn.getSignedInAccountFromIntent(data)
handleSignInResult(task)
}
}

我在 onActivityForResult 中遇到以下异常:

com.google.android.gms.common.api.ApiException: 10: 
at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source)
at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)

我已经尝试过 Android Auth key 和 Web Auth key。我总是超越异常(exception)。

请帮帮我。

最佳答案

此异常代码表示configuration problems与您的应用程序。我遇到了同样的问题,对我来说,它是通过这种方式解决的(在我的例子中,我想要使用 google 登录机制进行 firebase 身份验证):

  • 我使用了谷歌自动生成的网络客户端 ID,而不是我自己创建的(我什至没有要求谷歌生成它——它真的是自动生成的)
  • 我在我的 android 项目中更新了我的 JSON firebase 文件(这可能不是必需的,但我的选项用完了)
    一个可能有用的观察:
  • 如果你有这样一行...
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);

...可能您需要 Android 身份验证

我将复制我代码的重要部分(它正在运行并用 Java 编写),但我认为,根据您的异常消息,您的代码没有任何问题。

void onCreate(...) {
firebaseAuth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.web_server_client_id))
.requestEmail()
.build();
FirebaseUser currentUser = firebaseAuth.getCurrentUser();
firebaseAuthUpdateUI(currentUser);

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

findViewById(getLoginButtonId()).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});

}



protected void signIn(){
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SIGN_IN) {

GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
} else {
// Google Sign In failed, update UI appropriately
// ...
firebaseAuthUpdateUI(null);
}


}
}


private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
//Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());

AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
firebaseAuth.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");
user = firebaseAuth.getCurrentUser();
firebaseAuthUpdateUI(user);
} else {
// If sign in fails, display a message to the user.
//Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(SignInActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
user = null;
//firebaseAuthUpdateUI(null);
}

// ...
}
});
}

...

关于android - com.google.android.gms.common.api.ApiException : 10:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50001068/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com