Beispiel #1
0
        /// <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.V6.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());
        }
Beispiel #2
0
        /// <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.V6.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());
        }