简体   繁体   English

安装应用程序时无法登录谷歌播放游戏服务

[英]Cannot log-in to google play games service when app is installed

I made google-api-client with this code 我使用此代码制作了google-api-client

GoogleSignInOptions options = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestServerAuthCode(SERVER_CLIENT_ID)
            .build();

mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)                    
                .addApi(Auth.GOOGLE_SIGN_IN_API, options)
                .addApi(Games.API)                  
                .build();

and connect to service with this code 并使用此代码连接到服务

mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);

connection is successful but I can't get serverauthcode because mGoogleApiClient.hasConnectedApi(Games.API) returns false without any warning or error 连接成功但我无法获得serverauthcode,因为mGoogleApiClient.hasConnectedApi(Games.API)返回false而没有任何警告或错误

@Override
public void onConnected(Bundle bundle) {

     if (mGoogleApiClient.hasConnectedApi(Games.API)) {
        Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient).setResultCallback(
               new ResultCallback<GoogleSignInResult>() {
                   @Override
                   public void onResult(GoogleSignInResult googleSignInResult) {

                       // In this case, we are sure the result is a success.
                       GoogleSignInAccount signInAccount = googleSignInResult.getSignInAccount();                          
                       mAccountAuthCode = signInAccount.getServerAuthCode();    

                       Player player = Games.Players.getCurrentPlayer(mGoogleApiClient);
                       mAccountId = player.getPlayerId();
                       Log.i(MYTAG, "login success");           


                   }
               }
        );
    } 
    else
    {           
        Log.i(MYTAG, "connected but no Games.API Why!");            
    }

Strangely if I just disconnect and reconnect , mGoogleApiClient.hasConnectedApi(Games.API) return true and all things are fine. 奇怪的是,如果我只是断开连接并重新连接,mGoogleApiClient.hasConnectedApi(Games.API)将返回true并且一切正常。

Also if I just relaunch app mGoogleApiClient.hasConnectedApi(Games.API) return true and all things are fine. 此外,如果我只是重新启动应用程序mGoogleApiClient.hasConnectedApi(Games.API)返回true并且一切正常。

I wonder why I cannot connect google-play-games-service api with first try. 我想知道为什么我第一次尝试无法连接google-play-games-service api。

I'm using latest google play service sdk(10.2.4) 我正在使用最新的谷歌播放服务sdk(10.2.4)

any advice would be appreciated 任何意见,将不胜感激

You may refer with this thread . 你可以参考这个帖子 Try restarting your device. 尝试重启设备。 If that doesn't help, then clear the cache. 如果这没有帮助,那么清除缓存。 If issues persist, you can also try uninstalling and reinstalling Play Store app updates. 如果问题仍然存在,您还可以尝试卸载并重新安装Play商店应用更新。

For mGoogleApiClient.hasConnectedApi(Games.API) returns false , you may check this link: GoogleApiClient.isConnected() return always false 对于mGoogleApiClient.hasConnectedApi(Games.API)返回false ,您可以检查此链接: GoogleApiClient.isConnected()返回false

You need to add a couple callback listeners to the Builder (or GoogleApiClient). 您需要向Builder(或GoogleApiClient)添加几个回调侦听器。 What's most likely happening is that the login is failing because you don't have permissions yet. 最可能发生的是登录失败,因为您还没有权限。 You need to handle that failure so that the user can authorize your app. 您需要处理该失败,以便用户可以授权您的应用。

More reading: http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/ 更多阅读: http//www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one -宾语/

Hope this helps! 希望这可以帮助!

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

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