我做了谷歌的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