internal void RunCalls()
        {
            AdClients adClients = GetAllAdClients();

            // Get a host ad client ID, so we can run the rest of the samples.
            // Make sure it's a host ad client.
            AdClient exampleAdClient = FindAdClientForHost(adClients.Items);

            if (exampleAdClient != null)
            {
                // Custom Channels: List, Add, Update, Delete
                CustomChannels hostCustomChannels = GetAllCustomChannels(exampleAdClient.Id);
                CustomChannel  newCustomChannel   = AddCustomChannel(exampleAdClient.Id);
                newCustomChannel = UpdateCustomChannel(exampleAdClient.Id, newCustomChannel.Id);
                DeleteCustomChannel(exampleAdClient.Id, newCustomChannel.Id);

                // URL Channels: List, Add, Delete
                GetAllUrlChannels(exampleAdClient.Id);
                UrlChannel newUrlChannel = AddUrlChannel(exampleAdClient.Id);
                DeleteUrlChannel(exampleAdClient.Id, newUrlChannel.Id);

                GenerateReport(service, exampleAdClient.Id);
            }
            else
            {
                Console.WriteLine("No host ad clients found, unable to run remaining host samples.");
            }
        }
        /// <summary>
        /// This example adds a URL channel to a host ad client.
        /// </summary>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <returns>The created URL channel.</returns>
        private UrlChannel AddUrlChannel(string adClientId)
        {
            UrlChannel newUrlChannel = new UrlChannel();

            System.Random random = new System.Random(System.DateTime.Now.Millisecond);
            newUrlChannel.UrlPattern = "www.example.com/"
                                       + random.Next(0, 10000).ToString();

            Console.WriteLine("=================================================================");
            Console.WriteLine("Adding URL channel to ad client {0} with pattern {1}", adClientId,
                              newUrlChannel.UrlPattern);
            Console.WriteLine("=================================================================");

            // Create URL channel.
            UrlChannel urlChannel = this.service.Urlchannels
                                    .Insert(newUrlChannel, adClientId).Execute();

            Console.WriteLine("URL channel with id {0} and URL pattern {1} was created",
                              urlChannel.Id, urlChannel.UrlPattern);

            Console.WriteLine();

            // Return the URL Channel that was just created
            return(urlChannel);
        }
        /// <summary>
        /// This example deletes a URL channel on a host ad client.
        /// </summary>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <param name="urlChannelId">The ID for the URL channel to be deleted.</param>
        private void DeleteUrlChannel(string adClientId, string urlChannelId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Deleting URL channel {0}", urlChannelId);
            Console.WriteLine("=================================================================");

            // Delete custom channel
            UrlChannel urlChannel = this.service.Urlchannels.Delete(adClientId, urlChannelId).Execute();

            Console.WriteLine("Custom channel with id {0} was deleted.", urlChannelId);
            Console.WriteLine();
        }
Example #4
0
        /// <summary>
        /// Add a new URL channel to the host AdSense account.
        /// Documentation https://developers.google.com/adsensehost/v4.1/reference/urlchannels/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Adsensehost service.</param>
        /// <param name="adClientId">Ad client to which the new URL channel will be added.</param>
        /// <param name="body">A valid Adsensehost v4.1 body.</param>
        /// <returns>UrlChannelResponse</returns>
        public static UrlChannel Insert(AdsensehostService service, string adClientId, UrlChannel body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (adClientId == null)
                {
                    throw new ArgumentNullException(adClientId);
                }

                // Make the request.
                return(service.Urlchannels.Insert(body, adClientId).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Urlchannels.Insert failed.", ex);
            }
        }
        /// <summary>
        /// This example adds a URL channel to a host ad client.
        /// </summary>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        /// <returns>The created URL channel.</returns>
        private UrlChannel AddUrlChannel(string adClientId)
        {
            UrlChannel newUrlChannel = new UrlChannel();
            System.Random random = new System.Random(System.DateTime.Now.Millisecond);
            newUrlChannel.UrlPattern = "www.example.com/"
                + random.Next(0, 10000).ToString();

            Console.WriteLine("=================================================================");
            Console.WriteLine("Adding URL channel to ad client {0} with pattern {1}", adClientId,
                newUrlChannel.UrlPattern);
            Console.WriteLine("=================================================================");

            // Create URL channel.
            UrlChannel urlChannel = this.service.Urlchannels
                .Insert(newUrlChannel, adClientId).Execute();

            Console.WriteLine("URL channel with id {0} and URL pattern {1} was created",
                urlChannel.Id, urlChannel.UrlPattern);

            Console.WriteLine();

            // Return the URL Channel that was just created
            return urlChannel;
        }