Hello,
im trying to connect to Google ads api with GoogleAdsClient, after generation of token and refresh token with scopes adwords and business.manage, i can connect and create budget, but after arround 1h the token expire even with a refresh token.
looks like the refresh token of UserCredentials not taken in consideration for GoogleAdsClient.
//call to generate token
@GetMapping("/auth")
public String adsAuth() {
String redirect_uri = defaultHostname + "/ads/save-token";
ImmutableList<String> scopes = ImmutableList.<String>builder()
.add("
https://www.googleapis.com/auth/adwords", "
https://www.googleapis.com/auth/business.manage").build();
HttpTransport transport = new NetHttpTransport();
String clientId = googleAdsService.adsApiConfig().getClientId();
String clientSecret = googleAdsService.adsApiConfig().getClientSecret();
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, clientId, clientSecret, scopes).build();
GoogleAuthorizationCodeRequestUrl url = flow.newAuthorizationUrl();
url.setRedirectUri(redirect_uri);
url.setApprovalPrompt("force");
url.setAccessType("offline");
String authorize_url = url.build();
return "redirect:"+authorize_url;
}
//call to build GoogleAdsClient
Properties googleAdsProps = new Properties();
googleAdsProps.put(GoogleAdsClient.Builder.ConfigPropertyKey.LOGIN_CUSTOMER_ID.getPropertyKey(), loginCustomerId);
Credentials userCredentials =
UserCredentials.newBuilder()
.setClientId(clientId)
.setClientSecret(clientSecret)
.setAccessToken(new AccessToken(token, null))
.setRefreshToken(refreshToken)
.build();
GoogleAdsClient adsClient = GoogleAdsClient.newBuilder()
.setCredentials(userCredentials)
.fromProperties(googleAdsProps)
.setDeveloperToken("xxxxxxxxx")
.build();