I am using \"Google Sign-In\" in my app. Hence I use the class GoogleApiClient to get the user email and the ID token that I need for my backend.
When the user signs
Yes, answer above is correct. In general, any GoogleApiClient needs to be connected before it can return you any data. enableAutoManage helps you to call connect() / disconnect() automatically during onStart() / onStop(). If you don't use autoManage, you will need to connect() manually.
And even better, you should disconnect in a finally block.
Assuming you are not on the UI thread.
try {
ConnectionResult result = mGoogleApiClient.blockingConnect();
if (result.isSuccess()) {
GoogleSignInResult googleSignInResult =
Auth.GoogleSignInApi.silentSignIn(googleApiClient).await();
...
}
} finally {
mGoogleApiClient.disconnect();
}
And also, to clean up your code a little bit: 1. gso built from below configuration is identical to your pasted code above:
GoogleSignInOptions gso =
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(SERVER_CLIENT_ID)
.requestEmail()
.build();