I've obtained a refresh token with the help of GoogleAuthorizationCodeFlow with 'offline' access type as described here:
.
I'm saving the refreshToken in a DB for future use.
With the refresh token I'm able to get a credential with this statement:
Credential credential = new OfflineCredentials.Builder()
.forApi(OfflineCredentials.Api.ADWORDS)
.fromFile()
.withRefreshToken(specificRefresToken)
.build()
.generateCredential()
The problem I'm facing is that the credential expires after 1 hour.
In the documentation it states ' By default, our client libraries automatically refresh an expired access token.' Which utility do I need to use to get this functionality?
To play fair, after the credential is initialized I'm putting it into a pool so for the next AdWords API request I can reuse it.
So my getCredential method looks like that (is this additional check for expiration time required?):
Credential credential = initializedCredentials.get(
client.id)
if (credential != null && credential.expiresInSeconds > 50) {
return credential
}
//initialize credential and put into initializedCredentials for future use
....