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();
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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
"Google Ads API and AdWords 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/156db454-0c7f-4318-b446-f44917bab1cbn%40googlegroups.com.