google-plus - Android Google Auth 登录获取 ID token handleSignInResult :false

标签 google-plus google-authenticator

我正在像这样设置 GoogleSignInOptions 和 Google Api 客户端

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.server_client_ID))
            .build();

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .addApi(Plus.API)
            .build();

我的 Google Web 应用程序客户端 ID 如下所示:

 1020847812450-xxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com

但总是在 onActivityResult

    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }

返回错误

我哪里做错了:S

onStart 部分

    mGoogleApiClient.connect();
    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()) {
        // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
        // and the GoogleSignInResult will be available instantly.
        Log.d(TAG, "Got cached sign-in");
        // GoogleSignInResult result = opr.get();
        // handleSignInResult(result);
    } else {
        // If the user has not previously signed in on this device or the sign-in has expired,
        // this asynchronous branch will attempt to sign in the user silently.  Cross-device
        // single sign-on will occur in this branch.

        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(GoogleSignInResult googleSignInResult) {

                handleSignInResult(googleSignInResult);
            }
        });
    }

onStop 部分

protected void onStop() {
    super.onStop();
    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}

onHandleSignInResult

private void handleSignInResult(GoogleSignInResult result) {
    Log.e(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        final GoogleSignInAccount acct = result.getSignInAccount();
        Log.e(TAG, acct.getDisplayName());

    }
}

最佳答案

我也面临同样的问题。首先删除当前的 OAuth 客户端 ID,然后再创建一个 OAuth 客户端 ID。它对我有用。

关于google-plus - Android Google Auth 登录获取 ID token handleSignInResult :false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34264043/

相关文章:

android - 加上一键分享选项使一个空帖子

google-api - 如何获取 Google Plus 中帖子的评论?

node.js - 如何计算 TOTP 到期的秒数?

google-plus - 从 Google+ API 检索个人资料图片

ios - Google Plus iPhone API 无需离开应用程序即可登录和共享

regex - 使用正则表达式提取 OTP key

php - 拉维尔 5 : How to store extra attributes to user login session

google-authenticator - 是否有Google身份验证器API

php - Google 身份验证器扫描时条形码无效

ios - 用于像 Facebook 一样在墙上发帖的 Google plus API