Is there any way to get Google ad results such as clicks, impressions etc... for a specific campaign using campaign ID through Google ads API?. When I search for that I got results only for a list of campaigns. I have given the code that I used below for your reference.
private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
try (GoogleAdsServiceClient googleAdsServiceClient =
googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
String searchQuery =
+ "ad_group_criterion.criterion_id, "
+ "ad_group_criterion.keyword.text, "
+ "ad_group_criterion.keyword.match_type, "
+ "metrics.impressions, "
+ "metrics.clicks, "
+ "metrics.cost_micros "
+ "FROM keyword_view "
// Constructs the SearchGoogleAdsStreamRequest.
SearchGoogleAdsStreamRequest request =
SearchGoogleAdsStreamRequest.newBuilder()
.setCustomerId(Long.toString(customerId))
.setQuery(searchQuery)
.build();
System.out.println("request"+request);
// Creates and issues a search Google Ads stream request that will retrieve all of the
// requested field values for the keyword.
ServerStream<SearchGoogleAdsStreamResponse> stream = null;
try {
stream =
googleAdsServiceClient.searchStreamCallable().call(request);
System.out.println("stream"+stream);
} catch (Exception e) {
e.printStackTrace();
}
// Iterates through the results in the stream response and prints all of the requested
// field values for the keyword in each row.
try {
for (SearchGoogleAdsStreamResponse response : stream) {
System.out.println("response -"+response);
System.out.println("response -"+response.getResultsList());
for (GoogleAdsRow googleAdsRow : response.getResultsList()) {
Campaign campaign = googleAdsRow.getCampaign();
AdGroup adGroup = googleAdsRow.getAdGroup();
AdGroupCriterion adGroupCriterion = googleAdsRow.getAdGroupCriterion();
Metrics metrics = googleAdsRow.getMetrics();
System.out.printf(
"in ad group '%s' "
+ "with ID %d "
+ "in campaign '%s' "
+ "with ID %d "
+ "had %d impression(s), "
+ "%d click(s), "
+ "and %d cost (in micros) "
+ "during the last 7 days.%n",
adGroup.getName(),
adGroup.getId(),
campaign.getName(),
campaign.getId(),
metrics.getImpressions(),
metrics.getClicks(),
metrics.getCostMicros());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Vibeeshnan A.