The issue is not about how you configure your app's credentials.
The example is either not receiving a refresh token or not persisting it permanently. Once you are redirected to the URL built by the following url builder, you should receive back a refresh_token as well. This token should be persisted permanently to be used by the client library to refresh access tokens.
GoogleAuthorizationCodeRequestUrl urlBuilder =
new GoogleAuthorizationCodeRequestUrl(
secrets.getWeb().getClientId(),
secrets.getWeb().getRedirectUris().get(0),
scopes)
.setAccessType("offline")
.setApprovalPrompt("force");
There is probably a problem on the flow, we're making a few changes to the samples. I will try to address your problem.