According to google docx we have two methods
- SingOut
- RevokeAccess
I need second one
For this way google provide such method
public void revokeAccess() {
GoogleSignInOptions gso = getGoogleSignInOptions();
mGoogleApiClient = getGoogleApiClient(gso);
if (mGoogleApiClient.isConnected()) {
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
}
});
} else {
Logger.log(GoogleImplementation.class, "GoogleApiClient is not connected yet.", Logger.ERROR);
}
}
But everytime when i try to invoke it i get error
GoogleApiClient is not connected yet.
I found the same issue on stack and according to this as far as i understand i have to invoke revokeAccess() on the same object which i made LogIn()
Therefore question how i can to save this object? Or i misunderstand the consept?
What am i doing wrong?
EDIT
@NonNull
public GoogleApiClient getGoogleApiClient(GoogleSignInOptions gso) {
return new GoogleApiClient.Builder(context)
.enableAutoManage(activity, listenerConnection) <-----
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
EDIT 2
public void revokeAccess() {
GoogleSignInOptions gso = getGoogleSignInOptions();
mGoogleApiClient = getGoogleApiClient(gso);
if (mGoogleApiClient.isConnected()) {
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
}
});
} else {
mGoogleApiClient.connect();
Logger.log(GoogleImplementation.class, "GoogleApiClient is not connected yet.", Logger.ERROR);
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
Logger.log(GoogleImplementation.class, "signOut:onResult:" + status, Logger.ERROR);
}
});
}
}