我做了谷歌的API客户端使用此代码不能登录到Google Play游戏服务时,应用程序安装
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();
,并连接使用此代码服务
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
连接成功但我不能得到serverauthcode,因为 mGoogleApiClient.hasConnectedApi(Games.API)返回假 没有任何警告或错误
@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!");
}
奇怪的是,如果我只是断开并重新连接, mGoogleApiClient.hasConnectedApi(Games.API)返回true,所有的事情都很好。
此外,如果我刚刚重新启动应用程序 mGoogleApiClient.hasConnectedApi(Games.API)返回true,所有的事情都很好。
我想知道为什么我无法连接谷歌玩游戏服务API第一次尝试。
我使用的是最新的谷歌游戏服务SDK(10.2.4)
任何意见,将不胜感激
尝试禁用即时运行。转到设置并取消选中启用即时运行,然后启动应用程序。 – Sallu
Sallu //是即时运行Android Studio功能吗?我使用gradle直接构建我的apk并在控制台上使用adb进行部署。 – gguo
是的。转至文件 - >设置 - >构建,执行,部署 - >即时运行 - >取消选中第一个复选框 – Sallu