Пример #1
0
        /// <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.V5.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);
        }
Пример #2
0
        /// <summary>
        /// Gets the campaign.
        /// </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="campaignResourceName">The campaign resource.</param>
        /// <returns>The campaign.</returns>
        private static gagvr::Campaign GetCampaign(GoogleAdsClient client, long customerId,
                                                   string campaignResourceName)
        {
            // Get the GoogleAdsService.
            gagvs::GoogleAdsServiceClient googleAdsService = client.GetService(
                Services.V5.GoogleAdsService);

            // Create the search query.
            string searchQuery = "SELECT campaign.id, campaign.name, " +
                                 $"campaign.resource_name from campaign where " +
                                 $"campaign.resource_name='{campaignResourceName}'";

            // Retrieve the campaigns.
            PagedEnumerable <gagvs::SearchGoogleAdsResponse, gagvs::GoogleAdsRow>
            searchPagedResponse = googleAdsService.Search(customerId.ToString(), searchQuery);

            // Return the results.
            return(searchPagedResponse.First().Campaign);
        }
        /// <summary>
        /// Sets the starting date time for the new billing setup. Queries the customer's account
        /// to see if there are any approved billing setups. If there are any, the new billing setup
        /// may have a starting date time of any day in the future. If not, the billing setup must
        /// be set to start immediately.
        /// </summary>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="googleAdsService">The Google Ads service client.</param>
        /// <param name="billingSetup">The instance of BillingSetup whose starting date time will
        ///     be set.</param>
        private void SetBillingSetupStartDateTime(long customerId, GoogleAdsServiceClient
                                                  googleAdsService, BillingSetup billingSetup)
        {
            // Query to see if there are any existing approved billing setups. See
            // GetBillingSetup.cs for a more detailed example of requesting billing setup
            // information.
            string query = @"
                SELECT billing_setup.end_date_time
                FROM billing_setup
                WHERE billing_setup.status = 'APPROVED'
                ORDER BY billing_setup.end_date_time DESC";

            PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchResponse =
                googleAdsService.Search(customerId.ToString(), query);

            if (searchResponse.Any())
            {
                // If there are any existing approved billing setups, the new billing setup can
                // start immediately after the last.
                string lastEndingDateTimeString = searchResponse.First().BillingSetup.EndDateTime;

                // Check if the existing billing setup has no end date (i.e., is set to run
                // indefinitely).
                if (lastEndingDateTimeString == null)
                {
                    throw new Exception("Cannot set ending date time for the new " +
                                        "billing setup; the latest existing billing setup is set " +
                                        "to run indefinitely.");
                }

                DateTime lastEndingDateTime = DateTime.Parse(lastEndingDateTimeString);
                billingSetup.StartDateTime = lastEndingDateTime.AddDays(1).ToString("yyyy-MM-dd");
                billingSetup.EndDateTime   = lastEndingDateTime.AddDays(2).ToString("yyyy-MM-dd");
            }
            else
            {
                // If there are no existing approved billing setups, the only acceptable start time
                // is TimeType.Now.
                billingSetup.StartTimeType = TimeType.Now;
            }
        }
        /// <summary>
        /// Retrieves a feed item and its attribute values given a resource name.
        /// </summary>
        /// <param name="client">The Google Ads API client.</param>
        /// <param name="customerId">The client customer ID.</param>
        /// <param name="feedId">The feed ID that contains the target feed item.</param>
        /// <param name="feedItemId">The feed item ID that will be updated.</param>
        /// <returns>FeedItem with the given resource name.</returns>
        private FeedItem GetFeedItem(GoogleAdsClient client, long customerId,
                                     long feedId, long feedItemId)
        {
            // Gets the Google Ads service.
            GoogleAdsServiceClient googleAdsServiceClient = client.GetService(
                Services.V5.GoogleAdsService);

            // Constructs the resource name for the feed item.
            string feedItemResourceName = ResourceNames.FeedItem(customerId, feedId, feedItemId);

            // Constructs the query.
            string query = $@"
                SELECT feed_item.attribute_values
                FROM feed_item
                WHERE feed_item.resource_name = '{feedItemResourceName}'";

            // Issues the search request.
            PagedEnumerable <SearchGoogleAdsResponse, GoogleAdsRow> searchResponse =
                googleAdsServiceClient.Search(customerId.ToString(), query);

            // Returns the feed item attribute values.
            return(searchResponse.First().FeedItem);
        }