我正在根据此博客文章api-updates-for-sign-in-with-google
实施google flow的新登录然而,在登录时,我收到以下异常:
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)
时,我得到以下例外情况:
java.lang.NullPointerException: Appropriate Api was not requested.
我错过了什么或新流量不支持Games.API
?
答案 0 :(得分:3)
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
一些截图:
答案 1 :(得分:0)
在此community中提出了类似的错误。
错误消息似乎很清楚,目前这是不可能的:游戏有自己的登录流程。您是否有特殊原因使用它们?
以下是Implementing Sign-in In Your Games的参考资料。