Не удалось выполнить вход в GoogleApiClient

Я пытаюсь использовать Api для игр Google для игры в Android. Код, который я использую для подключения моего GoogleApiClient, поступает из образцов или документации Google Api.

Внутри моей реализации onConnectionFailed я пробовал два отдельных подхода:

    if (signInClicked || autoStartSignInFlow) {
        autoStartSignInFlow = false;
        signInClicked = false;
        resolvingConnectionFailure = true;

         // Attempt to resolve the connection failure using BaseGameUtils.
         // The R.string.signin_other_error value should reference a generic
         // error string in your strings.xml file, such as "There was
         // an issue with sign-in, please try again later."
        if (!BaseGameUtils.resolveConnectionFailure(this,
                apiClient, connectionResult,
                RC_SIGN_IN, R.string.signin_other_error)) {
            resolvingConnectionFailure = false;
        }
    }

Первый подход, приведенный выше, относится к образцу скелета TBMP. Это приводит к созданию диалогового окна с сообщением

Не удалось войти в систему. Проверьте подключение к сети и повторите попытку.

и соединение никогда не выполняется.

   if (connectionResult.hasResolution()) {
        // https://developers.google.com/android/guides/api-client under 'Handle connection
        // failures'. I don't know if this is solving the problem but it doesn't lead to
        // 'please check your network connection' message.
        try {
            if(LoggerConfig.ON) {
                Log.e(TAG, "onConnectionFailure, attempting to startResolutionForResult.");
            }
            resolvingConnectionFailure = true;
            connectionResult.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            // There was an error with the resolution intent. Try again.
            if(LoggerConfig.ON) {
                Log.e(TAG, "onConnectionFailure, there was an error with resolution intent");
            }
            apiClient.connect();
        }
    }

Во втором подходе он заканчивает вызов startResolutionForResult, который передает RESULT_SIGN_IN_FAILED в onActivityResult. Из документации

Код результата, отправленный обратно в вызывающую активность при сбое входа.

Не удалось выполнить попытку входа в службу Игр. Например, это может произойти, если сеть сломана, или учетная запись пользователя отключена, или согласие не может быть получено.

Это меня озадачивает, так как у меня нет проблем с тем, чтобы поток меток работал в образце. Тем не менее, в моей игре я никогда не предлагаю выбрать учетную запись Google до сбоя входа.

Для записи я пробовал все шаги здесь https://developers.google.com/games/services/android/troubleshooting, и он все еще терпит неудачу.

Как я могу разрешить эту ошибку для входа?

Ответы

Ответ 1

private GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create the Google Api Client with access to the Play Games services
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            // add other APIs and scopes here as needed
            .build();

    // ...
}

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

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

для дополнительной справки, пожалуйста, проверьте ссылку ссылка

Ответ 2

Попробуйте private GoogleApiClient mGoogleApiClient;

 mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                .addApi(LocationServices.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .build();

Вызвать mGoogleApiClient.connect(); в методе onStart().

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