简体   繁体   English

Google登录无法与Play Games Services启用功能一起使用,但不能与

[英]Google SignIn does not work with Play Games Services enables, but works without

First of all let's have a look at the code that works perfectly fine. 首先,让我们看一下运行良好的代码。 This is how we setup our Google Api Client: 这是我们设置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();

Then this for connecting: 然后这个用于连接:

// GPGS needs optional apparently, at least it crashes without. 
// Normal (non GPGS) SignIn works either way
googleApiClient.connect(SIGN_IN_MODE_OPTIONAL); 

Then we call login. 然后我们称为登录。 The overlay appears, I select my email, login runs through and all is fine: 出现覆盖,我选择我的电子邮件,登录通过,一切都很好:

public static void loginGoogleSDK()
{
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
    GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN);
}

Now there's the Google Play Games Services login which is quite similar, but does always return a User Cancelled error. 现在有一个非常相似的Google Play游戏服务登录名,但始终会返回“ 用户取消”错误。 The GPGS overlay appears, one can select an email, then it disappears and the error is given back: 出现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();

Connect and login are completely equal. 连接和登录完全相等。

The User Cancelled result code, comes back here: 用户取消的结果代码,返回此处:

@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....]


}

Does anybody know what's causing this and how we can get login with Google Player Games Services working? 有谁知道这是什么原因以及我们如何才能使用Google Player Games Services登录?

My code was 100% correct. 我的代码是100%正确的。

I had to add my email under "Testers" in the Google Play Developer Console under my Game. 我必须在游戏下方的Google Play开发者控制台中的“测试人员”下添加电子邮件。

This is not necessary for Google+ SignIn, but it is for games. 对于Google+登录,这不是必需的,但对于游戏来说,则是必需的。

我有类似的问题,但是从我的阅读中可以看出,您不能将Auth.GOOGLE_SIGN_IN_API与Games.API一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM