/// <summary> /// Gets the ad group ads. /// </summary> /// <param name="client">The client.</param> /// <param name="customerId">The customer identifier.</param> /// <param name="adGroupResourceNames">The ad group resource names.</param> /// <returns></returns> private static gagvr::AdGroupAd[] GetAdGroupAds(GoogleAdsClient client, long customerId, List <string> adGroupResourceNames) { // Get the GoogleAdsService. gagvs::GoogleAdsServiceClient googleAdsService = client.GetService( Services.V5.GoogleAdsService); // Create the search query. string searchQuery = $@"SELECT ad_group.id, ad_group_ad.ad.id, ad_group_ad.ad.expanded_text_ad.headline_part1, ad_group_ad.ad.expanded_text_ad.headline_part2, ad_group_ad.status, ad_group_ad.ad.final_urls, ad_group_ad.resource_name from ad_group_ad where ad_group_ad.resource_name IN (" + string.Join(",", adGroupResourceNames.Select( resourceName => $"'{resourceName}'")) + ")"; // Retrieve the ad group ads. PagedEnumerable <gagvs::SearchGoogleAdsResponse, gagvs::GoogleAdsRow> searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery); // Return the results. return(searchPagedResponse.Select(row => row.AdGroupAd).ToArray()); }
/// <summary> /// Gets the keywords. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupResourceName">The ad group criteria resource.</param> /// <returns>The ad group criteria.</returns> private static gagvr::AdGroupCriterion[] GetKeywords(GoogleAdsClient client, long customerId, List <string> adGroupCriteriaResourceNames) { // Get the GoogleAdsService. gagvs::GoogleAdsServiceClient googleAdsService = client.GetService( Services.V1.GoogleAdsService); string searchQuery = $@"SELECT ad_group.id, ad_group.status, ad_group_criterion.criterion_id, ad_group_criterion.keyword.text, ad_group_criterion.keyword.match_type FROM ad_group_criterion WHERE ad_group_criterion.type = 'KEYWORD' AND ad_group.status = 'ENABLED' AND ad_group_criterion.status IN ('ENABLED', 'PAUSED') AND ad_group_criterion.resource_name IN (" + string.Join(",", adGroupCriteriaResourceNames.Select( resourceName => $"'{resourceName}'")) + ")"; // Retrieve the ad group criteria. PagedEnumerable <gagvs::SearchGoogleAdsResponse, gagvs::GoogleAdsRow> searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery); // Return the results. return(searchPagedResponse.Select(row => row.AdGroupCriterion).ToArray()); }
/// <summary> /// Gets the campaign budget. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="budgetResourceName">The budget resource.</param> /// <returns>The campaign budget.</returns> private static gagvr::CampaignBudget GetBudget(GoogleAdsClient client, long customerId, string budgetResourceName) { // Get the GoogleAdsService. gagvs::GoogleAdsServiceClient googleAdsService = client.GetService( Services.V6.GoogleAdsService); // Create the search query. string searchQuery = "SELECT campaign_budget.id, campaign_budget.name, " + $"campaign_budget.resource_name from campaign_budget where " + $"campaign_budget.resource_name='{budgetResourceName}'"; // Retrieve the campaigns. PagedEnumerable <gagvs::SearchGoogleAdsResponse, gagvs::GoogleAdsRow> searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery); // Return the results. return(searchPagedResponse.First().CampaignBudget); }
/// <summary> /// Gets the ad group. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <param name="adGroupResourceName">The ad group resource.</param> /// <returns>The ad group.</returns> private static gagvr::AdGroup GetAdGroup(GoogleAdsClient client, long customerId, string adGroupResourceName) { // Get the GoogleAdsService. gagvs::GoogleAdsServiceClient googleAdsService = client.GetService( Services.V6.GoogleAdsService); // Create the search query. string searchQuery = "SELECT ad_group.id, ad_group.name, " + $"ad_group.resource_name from ad_group where " + $"ad_group.resource_name='{adGroupResourceName}'"; // Retrieve the ad groups. PagedEnumerable <gagvs::SearchGoogleAdsResponse, gagvs::GoogleAdsRow> searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery); // Return the results. return(searchPagedResponse.First().AdGroup); }