GoogleAPIClientSingle example
josh-burton opened this issue · comments
Josh Burton commented
Can you provide an example of how to use GoogleAPIClientSingle?
It seems if I subscribe to this single, and flatMap to another observable where I can use the client, the client is disconnected before the chain completes.
Patrick Löwenstein commented
Could you please provide the whole chain where the problem occurs? I'll look into it then.
Josh Burton commented
I'm attempting to use it like this:
GoogleAPIClientSingle.create(context, Auth.CREDENTIALS_API)
.flatMap(client -> Single.create(new SingleOnSubscribe<CredentialRequestResult>() {
@Override
public void subscribe(SingleEmitter<CredentialRequestResult> emitter) throws Exception {
CredentialRequest credentialRequest = new CredentialRequest.Builder()
.setPasswordLoginSupported(true)
.build();
Auth.CredentialsApi.request(client, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {
@Override
public void onResult(@NonNull CredentialRequestResult result) {
emitter.onSuccess(result);
}
});
}
}));
Patrick Löwenstein commented
The problem was that Single
immediately unsubscribes when onSuccess()
is called. I refactored it to GoogleApiClientFlowable
, which should work now.