java - 出现错误 10 后如何让 Google-Sign in 工作?
问题描述
我试图按照指南在我的应用程序上实施 Google 登录。 https://developers.google.com/identity/sign-in/android/start-integrating#add_google_play_services
但是,每次我尝试登录时都会收到错误 10,我知道这意味着它是开发人员错误,但是我无法弄清楚我做错了什么。我实现了所有代码,确保我有正确的包并更新了 Android Studio。
我尝试了来自多个为我的应用程序生成的签名包和 apk 的 SHA1 哈希的不同客户端 ID。我尝试了 Google 为您提供的用于登录的预生成的。有任何想法吗?
谷歌登录的意图
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());
}
}
解决方案
推荐阅读
- laravel-5.7 - 在 laravel 中创建表时出现迁移错误
- xml - 在 ws02 的迭代器中介器中获取所有同名标签值的属性
- php - 如何从 Monolog 消息中获取时间?
- r - 有效地计算独特的数据子集
- python - 使用 tkinter 仅在自己的框架中显示图像
- java - 问题:Shutterbug Screenshot 为每个屏幕截图创建一个新文件夹,而不是将它们保存在 1 个文件夹中
- css - 为 CKEditor 格式组合框中的项目设置样式?
- c++ - 在 C++ 协议缓冲区中具有相同类型的一个
- python - float() 的无效文字:
- ruby-on-rails - `disable_with` 防止双击