首页 > 解决方案 > Android 平台上的 Google+ API 和 Google+ 登录弃用和日落

问题描述

最近,我收到一封来自 Google 的电子邮件,内容是:

2019 年 3 月 7 日,所有 Google+ API 和 Google+ 登录将完全关闭。这将从 1 月下旬开始逐步关闭,最早在 2019 年 1 月 28 日对这些 API 的调用开始间歇性失败。

在电子邮件的以下部分:

XXX GP (api-project-123123123123) 加 v1 plus.people.get

我正在使用com.google.android.gms.common.api.GoogleApiClient它是用于提供登录功能的连接回调。

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES)
                .build();

对于排行榜和成就:

startActivityForResult(Games.Achievements.getAchievementsIntent(mGoogleApiClient), 0);
startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
                        "leaderboardX"), 0);

我的应用不依赖于此处已弃用的范围: https ://developers.google.com/+/mobile/android/api-deprecation

在 Github 存储库上的 Google Play 服务的新示例中: https ://github.com/playgameservices/android-basic-samples

您可以在以下代码片段中看到新的 Google 登录实现和游戏功能使用。

登录:

mGoogleSignInClient = GoogleSignIn.getClient(this,
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());

mGoogleSignInClient.silentSignIn().addOnCompleteListener(this,
        new OnCompleteListener<GoogleSignInAccount>() {
          @Override
          public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
            if (task.isSuccessful()) {
              Log.d(TAG, "signInSilently(): success");
              onConnected(task.getResult());
            } else {
              Log.d(TAG, "signInSilently(): failure", task.getException());
              onDisconnected();
            }
          }
        });

对于游戏功能:

@Override
  public void onShowAchievementsRequested() {
    mAchievementsClient.getAchievementsIntent()
        .addOnSuccessListener(new OnSuccessListener<Intent>() {
          @Override
          public void onSuccess(Intent intent) {
            startActivityForResult(intent, RC_UNUSED);
          }
        })
        .addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception e) {
            handleException(e, getString(R.string.achievements_exception));
          }
        });
  }

  @Override
  public void onShowLeaderboardsRequested() {
    mLeaderboardsClient.getAllLeaderboardsIntent()
        .addOnSuccessListener(new OnSuccessListener<Intent>() {
          @Override
          public void onSuccess(Intent intent) {
            startActivityForResult(intent, RC_UNUSED);
          }
        })
        .addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception e) {
            handleException(e, getString(R.string.leaderboards_exception));
          }
        });
  }

我在这里有点困惑,我是否必须实现新的登录和排行榜/成就 API?

我是否需要进行更改才能不受 Google+ API 和 Google+ 登录失效的影响?

标签: androidgoogle-plusgoogle-play-gamesgoogle-signin

解决方案


您粘贴的代码不依赖于 Google+ API,不应受到 Google+ 关闭的影响。

您是否在游戏的早期版本中使用过任何 PLUS 示波器,而这可能仍在某些用户设备上?如果您当前的代码没问题,也许只有一些非常旧的版本会受到影响。

在云开发者控制台,您项目的 API 部分,您应该能够查看 Google+ 或游戏 API 的流量水平,看看它们是否有可能影响大量用户。您还可以在那里打开 Google+ API 详细信息,以查看正在调用哪些特定方法。


推荐阅读