Java Android GoogleSignInAccount不保存配置文件信息,即所有get方法都返回null
我试图用谷歌实现一个简单的登录按钮。 我将登录选项设置为:Java Android GoogleSignInAccount不保存配置文件信息,即所有get方法都返回null,java,android,google-api,Java,Android,Google Api,我试图用谷歌实现一个简单的登录按钮。 我将登录选项设置为: googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .requestProfile() .build(); googleApiClient = new GoogleApiClient.Builder(th
googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestProfile()
.build();
googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API)
.build();
在“我的听众”按钮上单击:
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
startActivityForResult(signInIntent, REQUEST_CODE);
}
});
当我登录时,我的resultcode是RESULT\u OK,因此我可以毫无问题地浏览if
语句
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE)
{
if(resultCode == RESULT_OK)
{
GoogleSignInResult res = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount account = res.getSignInAccount();
info.setText(account.getDisplayName());
}else{
info.setText("failed");
}
}else{
}
}
问题在于此GoogleSignInAccount
对象:
GoogleSignInAccount account = res.getSignInAccount();
在此对象上调用的每个方法都返回null
。我这样做是为了证明:
编辑:
res.issucces()
返回true
在获取帐户信息之前,您能检查res.issucces()是否为true吗?是的,我忘了提到res.issucces()是否返回true即使我有相同问题,也可能重复?你解决了吗?