I have an issue about refresh user token expired time, I realize that user token can only use for one hour then it will expired, so I write a function to auto refresh token when it going to expired.
GoogleOAuth auth = dao.getGoogleAuth();
System.out.println(String.format("Auth expired date:%s",
new Date(auth.getExpirationTimeMillis()).toString()));
//get the original UserCredentials
UserCredentials credentials = auth.toUserCredentials();
credentials.refresh();
AccessToken accessToken = credentials.refreshAccessToken();
System.out.println("current time:" + new Date().toString());
System.out.println(String.format("Auth new expired date:%s",
accessToken.getExpirationTime().toString()));
GoogleOAuth newAuth = GoogleOAuth.newBuilder(credentials.getClientId())
.setClientSecret(config.getClientSecret()).setRefreshToken(accessToken.getTokenValue())
.setAccessToken(credentials.getAccessToken().getTokenValue())
.setExpirationTimeMillis(accessToken.getExpirationTime().getTime()).build();
biz.getMutator().mutateConnectGoogle(newAuth);
Collection<String> accountIds = newAuth.getAllAdAccounts(true);
GoogleCache.refreshAccountAndCampaignCache(newAuth, credentials, accessToken, accountIds);
Auth expired date:Thu Sep 10 13:35:09 CST 2020
current time:Thu Sep 10 12:41:48 CST 2020
Auth new expired date:Thu Sep 10 13:35:10 CST 2020
I got the new token after run the auto refresh function, but the expired time was not changed, I am not sure whats problem about it.