Ejemplo n.º 1
0
        /// <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></returns>
        private static AdsenseReportsGenerateResponse getPage(
            ReportsResource.GenerateRequest reportRequest, int startIndex, int pageSize)
        {
            reportRequest.StartIndex = startIndex;
            reportRequest.MaxResults = pageSize;

            // Run next page of report.
            return(reportRequest.Fetch());
        }
        /// <summary>
        ///  This example prints a report, using a filter for a specified ad client.
        /// </summary>
        /// <param name="service">AdSense service object on which to run the requests.</param>
        /// <param name="adClientId">The ID for the ad client to be used.</param>
        private void GenerateReport(AdSenseHostService service, 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);

            ReportsResource.GenerateRequest reportRequest
                = this.service.Reports.Generate(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",
                "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();
        }
Ejemplo n.º 3
0
        public List<AdExGoogleStats> GetAdxData()
        {
            List<AdExGoogleStats> stats = new List<AdExGoogleStats>();
            try
            {
                AdExchangeSellerService service_adex = new AdExchangeSellerService(new AdExchangeSellerService.Initializer()
                {
                    HttpClientInitializer = OauthCredentials,
                    ApplicationName = "Admixer Exchange",
                });
                ReportsResource.GenerateRequest gr = new ReportsResource.GenerateRequest(service_adex, StarDate, EndDate);
                gr.Metric = Metrics;
                gr.Dimension = Dimensions;
                gr.Sort = "DATE";
                gr.Locale = "en_US";
                Report report = gr.Execute();
                //stat = report.Rows.Cast<AdExGoogleStat>().ToList();
                foreach (var item in report.Rows)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(item.ElementAt(1))) continue;
                        AdExGoogleStats statobject = new AdExGoogleStats()
                        {
                            Date = DateTime.Parse(item.ElementAt(0)),
                            Id = Int64.Parse(item.ElementAt(1)),
                            TagName = item.ElementAt(2),
                            MatchedRequests = Int64.Parse(item.ElementAt(4)),
                            Clicks = Int32.Parse(item.ElementAt(5)),
                            CTR = decimal.Parse(item.ElementAt(6)),
                            eCPM = decimal.Parse(item.ElementAt(7)),
                            Revenue = decimal.Parse(item.ElementAt(8)),
                            Size = item.ElementAt(3),
                            Width = Int32.Parse(item.ElementAt(3).Substring(0, item.ElementAt(3).IndexOf('x'))),
                            Height = Int32.Parse(item.ElementAt(3).Substring(item.ElementAt(3).IndexOf('x') + 1, item.ElementAt(3).Length - (item.ElementAt(3).IndexOf('x') + 1))),
                            Requests = Int32.Parse(item.ElementAt(9))
                        };
                        stats.Add(statobject);
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("ex_GetAdxData", ex.Message);
                    }
                }


            }

            catch (Exception ex)
            {
                Logger.Write("ex_GetAdxData", ex.Message);
                stats = null;
            }
            Logger.Write("GetAdxData", "Adx Data received");
            return stats;
        }