我正在使用 Google Auth 登录并获取个人资料详细信息。
但我面临一个问题。onActivityResult
如果用户第一次进行身份验证,sdk 将有助于添加新帐户,一旦成功,它将重新调用
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount acct = result.getSignInAccount();
acct.getGivenName()
和acct.getFamilyName()
是null
。_
但是,如果我使用已经添加的帐户进行身份验证,acct.getGivenName()
并且acct.getFamilyName()
具有预期价值。
我的代码如下
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestId()
.requestProfile()
.build();
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mActivity)
.enableAutoManage(mActivity, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
startActivityForResult(signInIntent, REQUEST_CODE_GOOGLE_SIGN_IN);