用谷歌登录游戏服务 [英] Sign-In with google for games services
问题描述
I am implementing the new sign in with google flow according to this blog post: api-updates-for-sign-in-with-google
However on sign in I get the following exception:
IllegalStateException: Auth.GOOGLE_SIGN_IN_API cannot be used with Games.API
I am constructing my GoogleApiClient
like this:
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();
When I remove .addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
I get the following exceptoin:
java.lang.NullPointerException: Appropriate Api was not requested.
Am I missing something or the new flow does not support Games.API
?
IMO, you can refer to the following sample code:
...
@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();
}
}
...
More details at Accessing the Play Games Services APIs in Your Android Game
If your app gets java.lang.IllegalStateException: A fatal developer error has occurred. Check the logs for further information
, please read Troubleshooting Issues in Your Android Game
Some screenshots:
这篇关于用谷歌登录游戏服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!