gpt4 book ai didi

java - 收到错误 10 后如何让 Google-Sign 正常工作?

转载 作者:行者123 更新时间:2023-12-02 01:23:07 25 4
gpt4 key购买 nike

我尝试按照指南在我的应用上实现 Google Sign In。 https://developers.google.com/identity/sign-in/android/start-integrating#add_google_play_services

但是,每次我尝试登录时,我都会收到错误 10,我知道这意味着它是开发人员错误,但我无法弄清楚我做错了什么。我实现了所有代码,确保我拥有正确的包并更新了 Android Studio。

我尝试了来自 SHA1 哈希值的不同客户端 ID,这些哈希值来自为我的应用程序生成的多个签名包和 APK。我尝试了 Google 为您提供的预先生成的登录选项。有什么想法吗?

Google 登录 Intent

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(getString(R.string.server_client_id))
.build();

googleSignInClient = GoogleSignIn.getClient(getActivity(),gso);

Intent signInIntent = googleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 21);

OnActivityResult函数

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

if(requestCode == 21) {

Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);

}

else if (resultCode == RESULT_CANCELED)
{
Log.d("frag", "intent fired and something went wrong");

}
}

handleSignInResult 函数

    private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);

// Signed in successfully, show authenticated UI.

Log.d("frag", "Email of account is " + account.getEmail());

} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("ytsignin", "signInResult:failed code=" + e.getStatusCode());


}
}

最佳答案

在开发者控制台中检查SHA-1代码和包名称。大多数情况下,这就是导致错误 10 的原因,即“DEVELOPER_ERROR”。检查控制台中的 SHA-1 与运行签名报告后从 Android Studio 获取的 SHA-1。 enter image description here

关于java - 收到错误 10 后如何让 Google-Sign 正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57342323/

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