/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> public static void Run(AdsenseService adsense, string adClientId) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Running report for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Prepare report. var startDate = DateTime.Today.ToString(DateFormat); var endDate = DateTime.Today.AddDays(-7).ToString(DateFormat); var reportRequest = adsense.Reports.Generate(startDate, endDate); // Specify the desired ad client using a filter, as well as other parameters. reportRequest.Filter = new List<string> { "AD_CLIENT_ID==" + EscapeFilterParameter(adClientId) }; reportRequest.Metric = new List<string> { "PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE", "AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS" }; reportRequest.Dimension = new List<string> { "DATE" }; reportRequest.Sort = new List<string> { "+DATE" }; // Run report. var reportResponse = reportRequest.Fetch(); if (reportResponse.Rows != null && reportResponse.Rows.Count > 0) { displayHeaders(reportResponse.Headers); displayRows(reportResponse.Rows); } else { CommandLine.WriteLine("No rows returned."); } CommandLine.WriteLine(); }
/// <summary> /// List all URL channels in the specified ad client for this AdSense account. /// Documentation https://developers.google.com/adsense/v1.4/reference/urlchannels/list /// 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 Adsense service.</param> /// <param name="adClientId">Ad client for which to list URL channels.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>UrlChannelsResponse</returns> public static UrlChannels List(AdsenseService service, string adClientId, UrlchannelsListOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (adClientId == null) { throw new ArgumentNullException(adClientId); } // Building the initial request. var request = service.Urlchannels.List(adClientId); // Applying optional parameters to the request. request = (UrlchannelsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Urlchannels.List failed.", ex); } }
internal static void Main(string[] args) { Console.WriteLine("\nAdSense Management API Command Line Sample"); Console.WriteLine("==========================================\n"); GoogleWebAuthorizationBroker.Folder = "AdSense.Sample"; var credential = GoogleWebAuthorizationBroker .AuthorizeAsync(new ClientSecrets { ClientId = "INSERT_CLIENT_ID_HERE", ClientSecret = "INSERT_CLIENT_SECRET_HERE" }, new string[] { AdsenseService.Scope.Adsense }, "user", CancellationToken.None) .Result; // Create the service. var service = new AdsenseService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "AdSense Sample" }); // Execute Publisher calls ManagementApiConsumer managementApiConsumer = new ManagementApiConsumer(service, MaxListPageSize); managementApiConsumer.RunCalls(); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }
static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("AdSense Management API Command Line Sample"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new AdsenseService(auth); var accounts = GetAllAccounts.Run(service, MaxListPageSize); if (accounts.Items != null && accounts.Items.Count > 0) { // Get an example account ID, so we can run the following samples. var exampleAccountId = accounts.Items[0].Id; GetAccountTree.Run(service, exampleAccountId); GetAllAdClientsForAccount.Run(service, exampleAccountId, MaxListPageSize); } var adClients = GetAllAdClients.run(service, MaxListPageSize); if (adClients.Items != null && adClients.Items.Count > 0) { // Get an ad client ID, so we can run the rest of the samples. var exampleAdClientId = adClients.Items[0].Id; var adUnits = GetAllAdUnits.Run(service, exampleAdClientId, MaxListPageSize); if (adUnits.Items != null && adUnits.Items.Count > 0) { // Get an example ad unit ID, so we can run the following sample. var exampleAdUnitId = adUnits.Items[0].Id; GetAllCustomChannelsForAdUnit.Run(service, exampleAdClientId, exampleAdUnitId, MaxListPageSize); } var customChannels = GetAllCustomChannels.Run(service, exampleAdClientId, MaxListPageSize); if (customChannels.Items != null && customChannels.Items.Count > 0) { // Get an example custom channel ID, so we can run the following sample. var exampleCustomChannelId = customChannels.Items[0].Id; GetAllAdUnitsForCustomChannel.Run(service, exampleAdClientId, exampleCustomChannelId, MaxListPageSize); } GetAllUrlChannels.Run(service, exampleAdClientId, MaxListPageSize); GenerateReport.Run(service, exampleAdClientId); GenerateReportWithPaging.Run(service, exampleAdClientId, MaxReportPageSize); } CommandLine.PressAnyKeyToExit(); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> public static void Run(AdsenseService adsense, string adClientId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all URL channels for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Retrieve URL channel list in pages and display data as we receive it. string pageToken = null; UrlChannels urlChannelResponse = null; do { var urlChannelRequest = adsense.Urlchannels.List(adClientId); urlChannelRequest.MaxResults = maxPageSize; urlChannelRequest.PageToken = pageToken; urlChannelResponse = urlChannelRequest.Fetch(); if (urlChannelResponse.Items != null && urlChannelResponse.Items.Count > 0) { foreach (var urlChannel in urlChannelResponse.Items) { CommandLine.WriteLine("URL channel with pattern \"{0}\" was found.", urlChannel.UrlPattern); } } else { CommandLine.WriteLine("No URL channels found."); } pageToken = urlChannelResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxReportPageSize">The maximum page size to retrieve.</param> public static void Run(AdsenseService adsense, string adClientId, int maxReportPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Running paginated report for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Prepare report. var startDate = DateTime.Today.ToString(DateFormat); var endDate = DateTime.Today.AddDays(-7).ToString(DateFormat); var reportRequest = adsense.Reports.Generate(startDate, endDate); var pageSize = maxReportPageSize; var startIndex = 0; // Specify the desired ad client using a filter, as well as other parameters. reportRequest.Filter = new List<string> { "AD_CLIENT_ID==" + GenerateReport.EscapeFilterParameter(adClientId) }; reportRequest.Metric = new List<string> { "PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE", "AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS" }; reportRequest.Dimension = new List<string> { "DATE" }; reportRequest.Sort = new List<string> { "+DATE" }; // Run first page of report. var reportResponse = getPage(reportRequest, startIndex, pageSize); if (reportResponse.Rows == null || reportResponse.Rows.Count == 0) { CommandLine.WriteLine("No rows returned."); return; } // Display headers. GenerateReport.displayHeaders(reportResponse.Headers); // Display first page of results. GenerateReport.displayRows(reportResponse.Rows); var totalRows = Math.Min(int.Parse(reportResponse.TotalMatchedRows), RowLimit); for (startIndex = reportResponse.Rows.Count; startIndex < totalRows; startIndex += reportResponse.Rows.Count) { // Check to see if we're going to go above the limit and get as many results as we can. pageSize = Math.Min(maxReportPageSize, totalRows - startIndex); // Run next page of report. reportResponse = getPage(reportRequest, startIndex, pageSize); // If the report size changes in between paged requests, the result may be empty. if (reportResponse.Rows == null || reportResponse.Rows.Count == 0) { break; } // Display results. GenerateReport.displayRows(reportResponse.Rows); } CommandLine.WriteLine(); }
static void Main(string[] args) { // Display the header and initialize the sample. CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("AdSense Management API Command Line Sample"); // Register the authenticator. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); var credentials = PromptingClientCredentials.EnsureFullClientCredentials(); provider.ClientIdentifier = credentials.ClientId; provider.ClientSecret = credentials.ClientSecret; var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthentication); // Create the service. var service = new AdsenseService(auth); var accounts = GetAllAccounts.Run(service, MaxListPageSize); if (accounts.Items != null && accounts.Items.Count > 0) { // Get an example account ID, so we can run the following samples. var exampleAccountId = accounts.Items[0].Id; GetAccountTree.Run(service, exampleAccountId); GetAllAdClientsForAccount.Run(service, exampleAccountId, MaxListPageSize); } var adClients = GetAllAdClients.run(service, MaxListPageSize); if (adClients.Items != null && adClients.Items.Count > 0) { // Get an ad client ID, so we can run the rest of the samples. var exampleAdClientId = adClients.Items[0].Id; var adUnits = GetAllAdUnits.Run(service, exampleAdClientId, MaxListPageSize); if (adUnits.Items != null && adUnits.Items.Count > 0) { // Get an example ad unit ID, so we can run the following sample. var exampleAdUnitId = adUnits.Items[0].Id; GetAllCustomChannelsForAdUnit.Run(service, exampleAdClientId, exampleAdUnitId, MaxListPageSize); } var customChannels = GetAllCustomChannels.Run(service, exampleAdClientId, MaxListPageSize); if (customChannels.Items != null && customChannels.Items.Count > 0) { // Get an example custom channel ID, so we can run the following sample. var exampleCustomChannelId = customChannels.Items[0].Id; GetAllAdUnitsForCustomChannel.Run(service, exampleAdClientId, exampleCustomChannelId, MaxListPageSize); } GetAllUrlChannels.Run(service, exampleAdClientId, MaxListPageSize); GenerateReport.Run(service, exampleAdClientId); GenerateReportWithPaging.Run(service, exampleAdClientId, MaxReportPageSize); } CommandLine.PressAnyKeyToExit(); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="accountId">The ID for the account to be used.</param> public static void Run(AdsenseService adsense, string accountId) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Displaying AdSense account tree for {0}", accountId); CommandLine.WriteLine("================================================================="); // Retrieve account. var account = adsense.Accounts.Get(accountId).Fetch(); displayTree(account, 0); CommandLine.WriteLine(); }
/// <summary> /// List the payments for this AdSense account. /// Documentation https://developers.google.com/adsense/v1.4/reference/payments/list /// 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 Adsense service.</param> /// <returns>PaymentsResponse</returns> public static Payments List(AdsenseService service) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } // Make the request. return(service.Payments.List().Execute()); } catch (Exception ex) { throw new Exception("Request Payments.List failed.", ex); } }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> public static void Run(AdsenseService adsense, string adClientId) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Running report for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Prepare report. var startDate = DateTime.Today.ToString(DateFormat); var endDate = DateTime.Today.AddDays(-7).ToString(DateFormat); var reportRequest = adsense.Reports.Generate(startDate, endDate); // Specify the desired ad client using a filter, as well as other parameters. reportRequest.Filter = new List <string> { "AD_CLIENT_ID==" + EscapeFilterParameter(adClientId) }; reportRequest.Metric = new List <string> { "PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE", "AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS" }; reportRequest.Dimension = new List <string> { "DATE" }; reportRequest.Sort = new List <string> { "+DATE" }; // Run report. var reportResponse = reportRequest.Fetch(); if (reportResponse.Rows != null && reportResponse.Rows.Count > 0) { displayHeaders(reportResponse.Headers); displayRows(reportResponse.Rows); } else { CommandLine.WriteLine("No rows returned."); } CommandLine.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; }
/// <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); }
/// <summary> /// Dismiss (delete) the specified alert from the publisher's AdSense account. /// Documentation https://developers.google.com/adsense/v1.4/reference/alerts/delete /// 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 Adsense service.</param> /// <param name="alertId">Alert to delete.</param> public static void Delete(AdsenseService service, string alertId) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (alertId == null) { throw new ArgumentNullException(alertId); } // Make the request. service.Alerts.Delete(alertId).Execute(); } catch (Exception ex) { throw new Exception("Request Alerts.Delete failed.", ex); } }
/// <summary> /// Get a specific saved ad style from the user's account. /// Documentation https://developers.google.com/adsense/v1.4/reference/savedadstyles/get /// 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 Adsense service.</param> /// <param name="savedAdStyleId">Saved ad style to retrieve.</param> /// <returns>SavedAdStyleResponse</returns> public static SavedAdStyle Get(AdsenseService service, string savedAdStyleId) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (savedAdStyleId == null) { throw new ArgumentNullException(savedAdStyleId); } // Make the request. return(service.Savedadstyles.Get(savedAdStyleId).Execute()); } catch (Exception ex) { throw new Exception("Request Savedadstyles.Get failed.", ex); } }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of custom channels.</returns> public static CustomChannels Run(AdsenseService adsense, string adClientId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all custom channels for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Retrieve custom channel list in pages and display data as we receive it. string pageToken = null; CustomChannels customChannelResponse = null; do { var customChannelRequest = adsense.Customchannels.List(adClientId); customChannelRequest.MaxResults = maxPageSize; customChannelRequest.PageToken = pageToken; customChannelResponse = customChannelRequest.Fetch(); if (customChannelResponse.Items != null && customChannelResponse.Items.Count > 0) { foreach (var customChannel in customChannelResponse.Items) { CommandLine.WriteLine("Custom channel with code \"{0}\" and name \"{1}\" was found.", customChannel.Code, customChannel.Name); } } else { CommandLine.WriteLine("No custom channels found."); } pageToken = customChannelResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of custom channels, so that the main sample has something to run. return customChannelResponse; }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of custom channels.</returns> public static CustomChannels Run(AdsenseService adsense, string adClientId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all custom channels for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Retrieve custom channel list in pages and display data as we receive it. string pageToken = null; CustomChannels customChannelResponse = null; do { var customChannelRequest = adsense.Customchannels.List(adClientId); customChannelRequest.MaxResults = maxPageSize; customChannelRequest.PageToken = pageToken; customChannelResponse = customChannelRequest.Fetch(); if (customChannelResponse.Items != null && customChannelResponse.Items.Count > 0) { foreach (var customChannel in customChannelResponse.Items) { CommandLine.WriteLine("Custom channel with code \"{0}\" and name \"{1}\" was found.", customChannel.Code, customChannel.Name); } } else { CommandLine.WriteLine("No custom channels found."); } pageToken = customChannelResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of custom channels, so that the main sample has something to run. return(customChannelResponse); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of retrieved accounts.</returns> public static AdUnits Run(AdsenseService adsense, string adClientId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all ad units for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; AdUnits adUnitResponse = null; do { var adUnitRequest = adsense.Adunits.List(adClientId); adUnitRequest.MaxResults = maxPageSize; adUnitRequest.PageToken = pageToken; adUnitResponse = adUnitRequest.Fetch(); if (adUnitResponse.Items != null && adUnitResponse.Items.Count > 0) { foreach (var adUnit in adUnitResponse.Items) { CommandLine.WriteLine("Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" " + "was found.", adUnit.Code, adUnit.Name, adUnit.Status); } } else { CommandLine.WriteLine("No ad units found."); } pageToken = adUnitResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of ad units, so that the main sample has something to run. return(adUnitResponse); }
/// <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 ad clients.</returns> public static Accounts Run(AdsenseService adsense, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all AdSense accounts"); CommandLine.WriteLine("================================================================="); // Retrieve account list in pages and display data as we receive it. string pageToken = null; Accounts accountResponse = null; do { var accountRequest = adsense.Accounts.List(); accountRequest.MaxResults = maxPageSize; accountRequest.PageToken = pageToken; accountResponse = accountRequest.Fetch(); if (accountResponse.Items != null && accountResponse.Items.Count > 0) { foreach (var account in accountResponse.Items) { CommandLine.WriteLine("Account with ID \"{0}\" and name \"{1}\" was found.", account.Id, account.Name); } } else { CommandLine.WriteLine("No accounts found."); } pageToken = accountResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); // Return the last page of accounts, so that the main sample has something to run. return(accountResponse); }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="customChannelId">The ID for the custom channel to be used.</param> /// <param name="maxPageSize">The maximum page size to retrieve.</param> /// <returns>The last page of retrieved accounts.</returns> public static void Run(AdsenseService adsense, string adClientId, string customChannelId, int maxPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Listing all ad units for custom channel {0}", customChannelId); CommandLine.WriteLine("================================================================="); // Retrieve ad client list in pages and display data as we receive it. string pageToken = null; AdUnits adUnitResponse = null; do { var adUnitRequest = adsense.Customchannels.Adunits.List(adClientId, customChannelId); adUnitRequest.MaxResults = maxPageSize; adUnitRequest.PageToken = pageToken; adUnitResponse = adUnitRequest.Fetch(); if (adUnitResponse.Items != null && adUnitResponse.Items.Count > 0) { foreach (var adUnit in adUnitResponse.Items) { CommandLine.WriteLine("Ad unit with code \"{0}\", name \"{1}\" and status \"{2}\" " + "was found.", adUnit.Code, adUnit.Name, adUnit.Status); } } else { CommandLine.WriteLine("No ad units found."); } pageToken = adUnitResponse.NextPageToken; } while (pageToken != null); CommandLine.WriteLine(); }
/// <summary> /// List all saved ad styles in the user's account. /// Documentation https://developers.google.com/adsense/v1.4/reference/savedadstyles/list /// 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 Adsense service.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>SavedAdStylesResponse</returns> public static SavedAdStyles List(AdsenseService service, SavedadstylesListOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } // Building the initial request. var request = service.Savedadstyles.List(); // Applying optional parameters to the request. request = (SavedadstylesResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Savedadstyles.List failed.", ex); } }
/// <summary> /// Runs this sample. /// </summary> /// <param name="adsense">AdSense service object on which to run the requests.</param> /// <param name="adClientId">The ID for the ad client to be used.</param> /// <param name="maxReportPageSize">The maximum page size to retrieve.</param> public static void Run(AdsenseService adsense, string adClientId, int maxReportPageSize) { CommandLine.WriteLine("================================================================="); CommandLine.WriteLine("Running paginated report for ad client {0}", adClientId); CommandLine.WriteLine("================================================================="); // Prepare report. var startDate = DateTime.Today.ToString(DateFormat); var endDate = DateTime.Today.AddDays(-7).ToString(DateFormat); var reportRequest = adsense.Reports.Generate(startDate, endDate); var pageSize = maxReportPageSize; var startIndex = 0; // Specify the desired ad client using a filter, as well as other parameters. reportRequest.Filter = new List <string> { "AD_CLIENT_ID==" + GenerateReport.EscapeFilterParameter(adClientId) }; reportRequest.Metric = new List <string> { "PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE", "AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS" }; reportRequest.Dimension = new List <string> { "DATE" }; reportRequest.Sort = new List <string> { "+DATE" }; // Run first page of report. var reportResponse = getPage(reportRequest, startIndex, pageSize); if (reportResponse.Rows == null || reportResponse.Rows.Count == 0) { CommandLine.WriteLine("No rows returned."); return; } // Display headers. GenerateReport.displayHeaders(reportResponse.Headers); // Display first page of results. GenerateReport.displayRows(reportResponse.Rows); var totalRows = Math.Min(int.Parse(reportResponse.TotalMatchedRows), RowLimit); for (startIndex = reportResponse.Rows.Count; startIndex < totalRows; startIndex += reportResponse.Rows.Count) { // Check to see if we're going to go above the limit and get as many results as we can. pageSize = Math.Min(maxReportPageSize, totalRows - startIndex); // Run next page of report. reportResponse = getPage(reportRequest, startIndex, pageSize); // If the report size changes in between paged requests, the result may be empty. if (reportResponse.Rows == null || reportResponse.Rows.Count == 0) { break; } // Display results. GenerateReport.displayRows(reportResponse.Rows); } CommandLine.WriteLine(); }
/// <summary>Initializes a new instance of the <see cref="ManagementApiConsumer"/> /// class.</summary> <param name="service">AdSense service object on which to run the /// requests.</param> <param name="maxListPageSize">The maximum page size to retrieve.</param> public ManagementApiConsumer(AdsenseService service, int maxListPageSize) { this.service = service; this.maxListPageSize = maxListPageSize; }