Hi Team,
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.
customerId = 5114451929
campaignId = 16258888285
private void runExample(GoogleAdsClient googleAdsClient, long customerId) {
try (GoogleAdsServiceClient googleAdsServiceClient =
googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
String searchQuery =
"SELECT campaign.id, "
+ "campaign.name, "
+ "ad_group.id, "
+ "ad_group.name, "
+ "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 "
+ "WHERE campaign.id = 16258888285 ";
// 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();
}
}
}
Thanks & Regards,
Vibeeshnan A.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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/CAHW9OWnGyD1ysDKWkbkHL4dMqYYc3GDRgw370etAdgJDY953EA%40mail.gmail.com.