Hi Team,

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.

*Here's the code:*
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);

*The output got from Google:*
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.




-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/746e71c6-4de1-4506-bfaf-6b65d38d9782n%40googlegroups.com.

Reply via email to