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."); } }
internal void RunCalls() { Console.WriteLine("For the rest of the samples you'll need a Publisher ID. If you haven't associated an " + "AdSense account to your Host, set AssociationSession.cs as startup object and rebuild."); // Get publisher ID from user. Console.WriteLine("Insert Publisher ID"); string publisherId = Console.ReadLine(); if (string.IsNullOrEmpty(publisherId)) { return; } AdClients publisherAdClients = GetAllAdClients(publisherId); if (publisherAdClients.Items != null && publisherAdClients.Items.Count > 0) { // Get a host ad client ID, so we can run the rest of the samples. string examplePublisherAdClientId = publisherAdClients.Items[0].Id; GetAllAdUnits(publisherId, examplePublisherAdClientId); AdUnit adUnit = AddAdUnit(publisherId, examplePublisherAdClientId); adUnit = UpdateAdUnit(publisherId, examplePublisherAdClientId, adUnit.Id); DeleteAdUnit(publisherId, examplePublisherAdClientId, adUnit.Id); GenerateReport(publisherId, examplePublisherAdClientId); } }
/// <summary> /// Gets and prints all ad clients for the logged in user's default account. /// </summary> /// <returns>The last page of retrieved accounts.</returns> private AdClients GetAllAdClients() { Console.WriteLine("================================================================="); Console.WriteLine("Listing all ad clients for default account"); Console.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; AdClients adClientResponse = null; do { var adClientRequest = service.Accounts.Adclients.List(adSenseAccount.Id); adClientRequest.MaxResults = maxListPageSize; adClientRequest.PageToken = pageToken; adClientResponse = adClientRequest.Execute(); if (!adClientResponse.Items.IsNullOrEmpty()) { foreach (var adClient in adClientResponse.Items) { Console.WriteLine( "Ad client for product \"{0}\" with ID \"{1}\" was found.", adClient.ProductCode, adClient.Id); Console.WriteLine( "\tSupports reporting: {0}", adClient.SupportsReporting.Value ? "Yes" : "No"); } } else { Console.WriteLine("No ad clients found."); } pageToken = adClientResponse.NextPageToken; }while (pageToken != null); Console.WriteLine(); // Return the last page of ad clients, so that the main sample has something to run. return(adClientResponse); }
/// <summary> /// Displays all ad clients for an account. /// </summary> /// <param name="accountId">The ID for the account to be used.</param> private void DisplayAllAdClientsForAccount(string accountId) { Console.WriteLine("================================================================="); Console.WriteLine("Listing all ad clients for account {0}", accountId); Console.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; AdClients adClientResponse = null; do { var adClientRequest = service.Accounts.Adclients.List(accountId); adClientRequest.MaxResults = maxListPageSize; adClientRequest.PageToken = pageToken; adClientResponse = adClientRequest.Execute(); if (!adClientResponse.Items.IsNullOrEmpty()) { foreach (var adClient in adClientResponse.Items) { Console.WriteLine( "Ad client for product \"{0}\" with ID \"{1}\" was found.", adClient.ProductCode, adClient.Id); Console.WriteLine( "\tSupports reporting: {0}", adClient.SupportsReporting.Value ? "Yes" : "No"); } } else { Console.WriteLine("No ad clients found."); } pageToken = adClientResponse.NextPageToken; }while (pageToken != null); Console.WriteLine(); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of retrieved accounts.</returns> public static AdClients run(AdsenseService adsense, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all ad clients for default account"); CommandLine.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; AdClients adClientResponse = null; do { var adClientRequest = adsense.Adclients.List(); adClientRequest.MaxResults = maxPageSize; adClientRequest.PageToken = pageToken; adClientResponse = adClientRequest.Fetch(); if (adClientResponse.Items != null && adClientResponse.Items.Count > 0) { foreach (var adClient in adClientResponse.Items) { CommandLine.WriteLine("Ad client for product \"{0}\" with ID \"{1}\" was found.", adClient.ProductCode, adClient.Id); CommandLine.WriteLine("\tSupports reporting: {0}", adClient.SupportsReporting.Value ? "Yes" : "No"); } } else { CommandLine.WriteLine("No ad clients found."); } pageToken = adClientResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of ad clients, so that the main sample has something to run. return(adClientResponse); }