Java 在收到错误10后,如何让Google登录工作?
我一直在尝试按照指南在我的应用程序上实现谷歌登录。 然而,每次尝试登录时,我都会遇到错误10,我知道这意味着这是开发人员的错误,但我不知道我做错了什么。我实现了所有的代码,确保我有正确的软件包和更新的Android Studio 我尝试了来自SHA1散列的不同客户端ID,这些散列来自为我的应用程序生成的多个签名包和APK。我尝试了谷歌为您提供的用于登录的预生成版本。有什么想法吗 谷歌登录意图Java 在收到错误10后,如何让Google登录工作?,java,android,google-play,google-signin,Java,Android,Google Play,Google Signin,我一直在尝试按照指南在我的应用程序上实现谷歌登录。 然而,每次尝试登录时,我都会遇到错误10,我知道这意味着这是开发人员的错误,但我不知道我做错了什么。我实现了所有的代码,确保我有正确的软件包和更新的Android Studio 我尝试了来自SHA1散列的不同客户端ID,这些散列来自为我的应用程序生成的多个签名包和APK。我尝试了谷歌为您提供的用于登录的预生成版本。有什么想法吗 谷歌登录意图 GoogleSignInOptions gso = new GoogleSignInOptions.B
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");
}
}
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());
}
}
@覆盖
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
callbackManager.onActivityResult(请求代码、结果代码、数据);
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==21){
Task Task=GoogleSignIn.GetSignedAccountFromIntent(数据);
handleSignInResult(任务);
}
else if(resultCode==RESULT\u取消)
{
Log.d(“frag”,“意图被激发,出了问题”);
}
}
handleSignInResult函数
@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");
}
}
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());
}
}
private void handleSignInResult(任务完成任务){
试一试{
GoogleSignInAccount account=completedTask.getResult(ApiException.class);
//成功登录,显示已验证的UI。
Log.d(“frag”,“帐户的电子邮件是”+account.getEmail());
}捕获(APIE){
//ApiException状态代码表示详细的故障原因。
//有关更多信息,请参阅GoogleSignInstationCodes类参考。
Log.w(“ytsignin”、“signInResult:failed code=“+e.getStatusCode());
}
}
在开发者控制台中检查SHA-1代码和包名。大多数情况下,这是导致错误10的原因,即“开发人员错误”。
运行signingReport后,将控制台中的SHA-1与从Android Studio获得的对照检查