1

我根据这篇博客与谷歌的流程来实现新的登录:api-updates-for-sign-in-with-google登录在与谷歌游戏服务

但是在登录我得到以下异常:

IllegalStateException: Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API

我建设我GoogleApiClient这样的:

final GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
     .build(); 
mGoogleApiClient = new GoogleApiClient.Builder(this) 
     .enableAutoManage(this, this) 
     .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions) 
     .addApi(Games.API) 
     .build(); 

当我删除.addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)我得到以下exceptoin:

java.lang.NullPointerException: Appropriate Api was not requested.

我缺少的东西或新的流动不支持Games.API

+0

请阅读https://plus.google.com/+EtienneLawlor/posts/AB9rq2B69k3 – BNK

+0

而这个链接http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing -in.html,你可以注意'问题:询问不必要的作用域'和'解决方案:只询问你需要的作用域' – BNK

+0

我在这里要求什么不必要的范围? – maclir

回答

0

在这个community中有一个类似的错误。

错误消息似乎很清楚,目前这是不可能的:游戏有它自己的登录流程。是否有一个特定的原因,你使用两个?

这是Implementing Sign-in In Your Games的参考。

+1

当我删除GOOGLE_SIGN_IN_API时,我得到这个exceptoin:java.lang.NullPointerException :没有要求适当的Api。 – maclir

2

IMO,你可以参考下面的示例代码:

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

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .enableAutoManage(this, this) 
      .addApi(Games.API).addScope(Games.SCOPE_GAMES) 
      .build(); 
} 

@Override 
protected void onStart() { 
    super.onStart(); 
    mGoogleApiClient.connect(); 
} 

@Override 
protected void onStop() { 
    super.onStop(); 
    mGoogleApiClient.disconnect(); 
} 


@Override 
public void onConnected(Bundle bundle) { 
    Log.i("Result", "onConnected"); 
} 

@Override 
public void onConnectionSuspended(int i) { 
    // Attempt to reconnect 
    mGoogleApiClient.connect(); 
} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 
    Log.e("Result", "onConnectionFailed"); 

    // If the connection failed, in most of time this means user hasn't logined yet 
    // In this case invoke the `startResolutionForResult` will launch the login dialog and account picker 
    try { 
     if (connectionResult.hasResolution()) { 
      connectionResult.startResolutionForResult(m_activity, RC_SIGN_IN); 
     } 
    } catch (IntentSender.SendIntentException e) { 
     e.printStackTrace(); 
    } 
} 
... 

更多细节在Accessing the Play Games Services APIs in Your Android Game

如果您的应用程序变得java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information,请阅读Troubleshooting Issues in Your Android Game

一些截图:

enter image description here enter image description here

+1

此解决方案未使用[新登录流程](http://android-developers.blogspot.se/2015/12/api-updates-for-sign-in-with-google.html) – maclir

+1

@maclir The游戏玩游戏有自己的登录流程,所以'新登录流程'在这里不是必要的。 – jayatubi

+0

@jayatubi和maclir:请阅读[本博客](https://android-developers.googleblog。com/2016/12/games-authentication-adopt-google.html)“2017年初玩游戏服务将会发生一些变化” – BNK