[英]How to make Log Out from Google LogIn?
According to google docx we have two methods 根据google docx,我们有两种方法
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.
GoogleApiClient尚未连接。
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()
我在堆栈上发现了相同的问题 ,据我所知,我必须在我制作
LogIn()
的同一对象上调用revokeAccess()
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 编辑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);
}
});
}
}
在每个不同的活动中,您应该连接您的GoogleApiClient,它不会跨活动保持连接状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.