package com.foobar.google.ads;
import com.google.ads.googleads.lib.GoogleAdsClient;
import com.google.ads.googleads.v1.errors.GoogleAdsError;
import com.google.ads.googleads.v1.errors.GoogleAdsException;
import com.google.ads.googleads.v1.services.*;
import java.io.FileNotFoundException;
import java.io.IOException;
public class GetAdGroupCriterionSimulations {
private static final int PAGE_SIZE = 1_000;
public static void main(String[] args) {
long customerId = <CUSTOMER_ID>;
GoogleAdsClient googleAdsClient;
try {
googleAdsClient = GoogleAdsClient.newBuilder().fromPropertiesFile().build();
System.out.printf("Credentials: %s%n", googleAdsClient.getCredentials().toString());
} catch (FileNotFoundException fnfe) {
System.err.printf(
"Failed to load GoogleAdsClient configuration from file. Exception: %s%n", fnfe);
return;
} catch (IOException ioe) {
System.err.printf("Failed to create GoogleAdsClient. Exception: %s%n", ioe);
return;
}
try {
new GetAdGroupCriterionSimulations().runExample(googleAdsClient, customerId);
} catch (GoogleAdsException gae) {
// GoogleAdsException is the base class for most exceptions thrown by an API request.
// Instances of this exception have a message and a GoogleAdsFailure that contains a
// collection of GoogleAdsErrors that indicate the underlying causes of the
// GoogleAdsException.
System.err.printf(
"Request ID %s failed due to GoogleAdsException. Underlying errors:%n",
gae.getRequestId());
int i = 0;
for (GoogleAdsError googleAdsError : gae.getGoogleAdsFailure().getErrorsList()) {
System.err.printf(" Error %d: %s%n", i++, googleAdsError);
}
}
}
/**
* Runs the example.
*
* @param googleAdsClient the Google Ads API client.
* @param customerId the client customer ID.
* @throws GoogleAdsException if an API request failed with one or more service errors.
*/
private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
try (GoogleAdsServiceClient googleAdsServiceClient =
googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
SearchGoogleAdsRequest request =
SearchGoogleAdsRequest.newBuilder()
.setCustomerId(Long.toString(customerId))
.setPageSize(PAGE_SIZE)
.setQuery("SELECT ad_group_criterion_simulation.ad_group_id, ad_group_criterion_simulation.criterion_id FROM ad_group_criterion_simulation")
.build();
// Issues the search request.
GoogleAdsServiceClient.SearchPagedResponse searchPagedResponse = googleAdsServiceClient.search(request);
// Iterates over all rows in all pages and prints the requested field values in each row.
for (GoogleAdsRow googleAdsRow : searchPagedResponse.iterateAll()) {
System.out.printf(
"Ad group criterion simulation cpc bid point for ad group %s and criterion %s.%n",
googleAdsRow.getAdGroupCriterionSimulation().getAdGroupId().getValue(),
googleAdsRow.getAdGroupCriterionSimulation().getCriterionId().getValue());
}
}
}
}
Enter code here...Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.
Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/
Hi Robert,
Could you share the details of requests you were making with the AdWords API that were successful? That would help our investigation.
Thank you!
Ben, Google Ads API Team