我已通过本指南集成了 Google SignIn ( https://developers.google.com/identity/sign-in/android/start-integrating )。
我已经完成了这样的设置:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken(AppActivity.this.getResources().getString(R.string.server_client_id))
.build();
GoogleSignIn.googleApiClient = new GoogleApiClient.Builder(this)
.addOnConnectionFailedListener(this)
.addConnectionCallbacks(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
使用以下代码登录可以正常工作:
public static void loginGoogleSDK()
{
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
GameApplication.getActivity().startActivityForResult(signInIntent, RC_SIGN_IN);
}
出现登录界面,我选择一个帐户并登录。一切正常。
然后我尝试在本指南之后使用以下代码调用注销( https://developers.google.com/identity/sign-in/android/disconnect ),但我总是收到错误消息:无法注销,因为尚未登录。
Auth.GoogleSignInApi.signOut(googleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
System.out.println("Google SDK Sign Out Access Status:" + status);
}
});
奇怪的是,如果我再次调用login,它会自动成功,并且我无法再次选择帐户。因此,登录仍然有效,我无法注销。
最佳答案
根据 enableAutoManage documentation ,包括它:
Enables automatic lifecycle management in a support library FragmentActivity that connects the client in
onStart()
and disconnects it inonStop()
.It handles user recoverable errors appropriately and calls
onConnectionFailed(ConnectionResult)
on theunresolvedConnectionFailedListener
if theConnectionResult
has no resolution. This eliminates most of the boiler plate associated with usingGoogleApiClient
.
不包含enableAutoManage()
,如 Add Sign In guide确实如此,您的 GoogleApiClient
从未真正连接,导致您遇到错误。
如果您不想使用enableAutoManage()
,您可以按照 manually manage connections 的说明进行操作。包括提供 ConnectionCallbacks
和 OnConnectionFailedListener
的实现。
关于java - Android 上的 Google 登录 - 由于未登录而无法注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39195908/