/// <summary>
        /// Returns a page of results, defined by the request and page parameters.
        /// </summary>
        /// <param name="reportRequest">An instance of the Generate request for the report.</param>
        /// <param name="startIndex">The starting index for this page.</param>
        /// <param name="pageSize">The maximum page size.</param>
        /// <returns>A page of results</returns>
        public static AdsenseReportsGenerateResponse GetPage(
            AccountsResource.ReportsResource.GenerateRequest reportRequest, int startIndex, int pageSize)
        {
            reportRequest.StartIndex = startIndex;
            reportRequest.MaxResults = pageSize;

            // Run next page of report.
            return(reportRequest.Execute());
        }
        /// <summary>
        /// This example retrieves a report for the specified publisher ad client.
        ///
        /// Note that the statistics returned in these reports only include data from ad
        /// units created with the AdSense Host API v4.x.
        /// </summary>
        /// <param name="accountId">The ID of the publisher account on which to run the report.</param>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        private void GenerateReport(string accountId, string adClientId)
        {
            Console.WriteLine("=================================================================");
            Console.WriteLine("Running report for ad client {0}", adClientId);
            Console.WriteLine("=================================================================");

            // Prepare report.
            var startDate = DateTime.Today.ToString(DateFormat);
            var endDate   = DateTime.Today.AddDays(-7).ToString(DateFormat);

            AccountsResource.ReportsResource.GenerateRequest reportRequest
                = this.service.Accounts.Reports.Generate(accountId, startDate, endDate);

            // Specify the desired ad client using a filter, as well as other parameters.
            // A complete list of metrics and dimensions is available on the documentation.

            reportRequest.Filter = new List <string> {
                "AD_CLIENT_ID=="
                + ReportHelper.EscapeFilterParameter(adClientId)
            };
            reportRequest.Metric = new List <string> {
                "PAGE_VIEWS", "AD_REQUESTS", "AD_REQUESTS_COVERAGE",
                "CLICKS", "AD_REQUESTS_CTR", "COST_PER_CLICK", "AD_REQUESTS_RPM", "EARNINGS"
            };
            reportRequest.Dimension = new List <string> {
                "DATE"
            };

            //A list of dimensions to sort by: + means ascending, - means descending
            reportRequest.Sort = new List <string> {
                "+DATE"
            };

            // Run report.
            Report reportResponse = reportRequest.Execute();

            if (reportResponse.Rows != null && reportResponse.Rows.Count > 0)
            {
                ReportHelper.displayHeaders(reportResponse.Headers);
                ReportHelper.displayRows(reportResponse.Rows);
            }
            else
            {
                Console.WriteLine("No rows returned.");
            }

            Console.WriteLine();
        }