首先让我们看一下运行完美的代码。这就是我们设置 Google Api 客户端的方式:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id))
.build();
GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
然后这个用于连接:
// GPGS needs optional apparently, at least it crashes without.
// Normal (non GPGS) SignIn works either way
googleApiClient.connect(SIGN_IN_MODE_OPTIONAL);
然后我们调用登录。出现覆盖层,我选择我的电子邮件,登录运行,一切都很好:
public static void loginGoogleSDK()
{
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN);
}
<小时/>
现在,Google Play 游戏服务登录非常相似,但总是返回用户已取消错误。 GPGS 覆盖出现,可以选择一封电子邮件,然后它消失并返回错误:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestEmail()
.requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id))
.build();
GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
连接和登录完全等同。
用户已取消结果代码返回此处:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// cancelled = true when using GPGS
GameLog.i("On Activity Result called, cancelled? " + (resultCode == RESULT_CANCELED) );
// [Other code for handling login....]
}
有谁知道导致此问题的原因以及我们如何才能正常登录 Google Player Games Services?
最佳答案
我的代码 100% 正确。
我必须在我的游戏下的 Google Play 开发者控制台的“测试人员”下添加我的电子邮件。
这对于 Google+ 登录来说不是必需的,但对于游戏来说是必需的。
关于java - Google 登录在启用 Play 游戏服务的情况下无法使用,但在未启用 Play 游戏服务的情况下也可以使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44856951/