我正在try 将谷歌登录整合到我的应用程序中.我没有后端服务器,我只是在我的应用程序中获取登录谷歌账户的详细信息.

我第一次try 使用Google Sign In Example,但出现了一个错误(除了打印下面的stacktrace之外,没有进行任何代码更改).我只是使用了示例Signalivity,因为我没有后端服务器.

 Exception com.google.android.gms.common.api.ApiException: 12500: 
 at com.google.android.gms.common.internal.zzb.zzz(Unknown Source)
 at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(Unknown Source)
 at com.ewise.android.api.MainActivity.onActivityResult(SignInActivity.java:89)     at android.app.Activity.dispatchActivityResult(Activity.java:7010)
 at android.app.ActivityThread.deliverResults(ActivityThread.java:4187)
 at android.app.ActivityThread.handleSendResult(ActivityThread.java:4234)
 at android.app.ActivityThread.-wrap20(ActivityThread.java)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6316)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

密码

 public class SignInActivity extends AppCompatActivity implements
         View.OnClickListener {

     private static final String TAG = "SignInActivity";
     private static final int RC_SIGN_IN = 9001;

     private GoogleSignInClient mGoogleSignInClient;
     private TextView mStatusTextView;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);

         // Views
         mStatusTextView = findViewById(R.id.status);

         // Button listeners
         findViewById(R.id.sign_in_button).setOnClickListener(this);
         findViewById(R.id.sign_out_button).setOnClickListener(this);
         findViewById(R.id.disconnect_button).setOnClickListener(this);

         // [START configure_signin]
         // Configure sign-in to request the user's ID, email address, and basic
         // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
         GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                 .requestEmail()
                 .build();
         // [END configure_signin]

         // [START build_client]
         // Build a GoogleSignInClient with the options specified by gso.
         mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
         // [END build_client]

         // [START customize_button]
         // Set the dimensions of the sign-in button.
         SignInButton signInButton = findViewById(R.id.sign_in_button);
         signInButton.setSize(SignInButton.SIZE_STANDARD);
         signInButton.setColorScheme(SignInButton.COLOR_LIGHT);
         // [END customize_button]
     }

     @Override
     public void onStart() {
         super.onStart();

         // [START on_start_sign_in]
         // Check for existing Google Sign In account, if the user is already signed in
         // the GoogleSignInAccount will be non-null.
         GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
         updateUI(account);
         // [END on_start_sign_in]
     }

     // [START onActivityResult]
     @Override
     public void onActivityResult(int request密码, int result密码, Intent data) {
         super.onActivityResult(request密码, result密码, data);

         // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
         if (request密码 == 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);
         }
     }
     // [END onActivityResult]

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

             // Signed in successfully, show authenticated UI.
             updateUI(account);
         } catch (ApiException e) {
             // The ApiException status code indicates the detailed failure reason.
             // Please refer to the GoogleSignInStatus密码s class reference for more information.
             Log.w(TAG, "signInResult:failed code=" + e.getStatus密码());
             e.printStackTrace();
             updateUI(null);
         }
     }
     // [END handleSignInResult]

     // [START signIn]
     private void signIn() {
         Intent signInIntent = mGoogleSignInClient.getSignInIntent();
         startActivityForResult(signInIntent, RC_SIGN_IN);
     }
     // [END signIn]

     // [START signOut]
     private void signOut() {
         mGoogleSignInClient.signOut()
                 .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {
                         // [START_EXCLUDE]
                         updateUI(null);
                         // [END_EXCLUDE]
                     }
                 });
     }
     // [END signOut]

     // [START revokeAccess]
     private void revokeAccess() {
         mGoogleSignInClient.revokeAccess()
                 .addOnCompleteListener(this, new OnCompleteListener<Void>() {
                     @Override
                     public void onComplete(@NonNull Task<Void> task) {
                         // [START_EXCLUDE]
                         updateUI(null);
                         // [END_EXCLUDE]
                     }
                 });
     }
     // [END revokeAccess]

     private void updateUI(@Nullable GoogleSignInAccount account) {
         if (account != null) {
             mStatusTextView.setText(getString(R.string.signed_in_fmt, account.getDisplayName()));

             findViewById(R.id.sign_in_button).setVisibility(View.GONE);
             findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
         } else {
             mStatusTextView.setText(R.string.signed_out);

             findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
             findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
         }
     }

     @Override
     public void onClick(View v) {
         switch (v.getId()) {
             case R.id.sign_in_button:
                 signIn();
                 break;
             case R.id.sign_out_button:
                 signOut();
                 break;
             case R.id.disconnect_button:
                 revokeAccess();
                 break;
         }
     }
  }

据我所知,这个问题可能是由SHA1 Generation引起的.

我跟踪了完整的guide个,但显然不起作用.

我从gradle signingReport复制了SHA1

Variant: debug
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: release
Config: none
----------
Variant: debugAndroidTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047
----------
Variant: debugUnitTest
Config: debug
Store: /Users/user/.android/debug.keystore
Alias: AndroidDebugKey
MD5: A3:16:3F:43:75:FE:07:62:6D:8D:CC:DD:21:9F:FA:1A
SHA1: 7B:21:26:7F:D8:18:BB:0E:36:1C:82:DD:B7:28:5F:C1:2F:5C:E4:EA
Valid until: Saturday, August 31, 2047

可能的原因是什么?

谢谢

另外,这可能是一个可能的原因吗?

Google Play services out of date.  Requires 11720000 but found 10932470

推荐答案

Simply update your Google Play Services to the latest version (or 11720000 in this case). If you are using AVD, Nexus 5 and 5X images support Google Play. Once the emulator is up and running, go to the Extended Controls Menu > Google Play then update.

Android相关问答推荐

将动作传递给嵌套的可组合物

RemoteActivityHelper.startRemoteActivity不适用于Android Wear OS 4模拟器

如何将两个变量传递给Nav主机,然后将其传递给另一个屏幕?

Android可绘制边框删除底线

如何在Jetpack Compose中将对象的移动从一个路径平滑地切换到另一个路径?

Jetpack Compose:根据盒子中的最大视图固定宽度和高度

React-Native Manifest 合并失败并出现多个错误

是什么导致调用 Firebase 服务器?

具有管理员权限的 Kotlin 中的多用户系统

为什么我要使用 $version 而不是2.7.0?

无法找到方法 ''java.io.File > org.jetbrains.kotlin.gradle.tasks.KotlinCompile.getDestinationDir()

Jetpack Compose 部分或开放侧边框

记住或不记得derivedStateOf

这是 let 函数的正确用法吗?

如何将房间数据库导出到 .CSV

如何在 kotlin 的 android room DB 中设置一对多关系

WindowManager 内的 RecyclerView 不更新

基线配置文件 x R8/Proguard

如何在 Kotlin 的片段中制作图像列表?

当我点击这个按钮时,我想使布尔值(boolean)为真.并将其传递给函数,以便在屏幕上显示内容