Android Google Auth登录获取ID令牌handleSignInResult:false [英] Android Google Auth Sign In get Id token handleSignInResult:false

查看:330
本文介绍了Android Google Auth登录获取ID令牌handleSignInResult:false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am setting GoogleSignInOptions and Google Api Client like this

    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网络应用客户端ID如下:

and my google web app client id like this:

 1020847812450-xxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com

但始终位于onActivityResult

but always at 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

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.它对我有用.

I am also facing the same issue.First remove the current OAuth client ID,after that create one more OAuth client ID.Its worked for me.

这篇关于Android Google Auth登录获取ID令牌handleSignInResult:false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆