using System; using System.Net; using System.Web; using System.Xml; /** * Sample code to generate AFC aggregate report through Adsense API */ namespace AdSenseApi { public class GenerateAFCAggregateReport { public static void MainGenerateAFCAggregateReport() { try { // initialize service serverReportService.ReportServiceService service = new serverReportService.ReportServiceService(); // set the headers string developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; string developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; string clientId = "ca-pub-REPLACE WITH CLIENT'S ID"; service.developer_emailValue = new serverReportService.developer_email(); service.developer_emailValue.Text = new string[] { developerEmail }; service.developer_passwordValue = new serverReportService.developer_password(); service.developer_passwordValue.Text = new string[] { developerPassword }; service.client_idValue = new serverReportService.client_id(); service.client_idValue.Text = new string[] { clientId }; serverReportService.DateRange dateRange = new serverReportService.DateRange(); DateTime start = new DateTime(2005, 11, 20); DateTime end = new DateTime(2006, 2, 20); dateRange.startDate = start; dateRange.endDate = end; dateRange.isPredefined = false; serverReportService.AFCAggregateReport report = new serverReportService.AFCAggregateReport(); report.dateRange = dateRange; report.unit = "Page"; report.outputFormat = "CSV_Excel"; // getting report. serverReportService.ReportData result = service.generateReport(report); // displays the results. Console.WriteLine("#row : {0}, #col : {1}", result.rowCount, result.columnCount); Console.WriteLine("data :"); Console.WriteLine("{0}", result.data); } catch (System.Web.Services.Protocols.SoapException e) { // displays errors Console.WriteLine("Report generation failed"); Console.WriteLine("message : {0}", e.Message); Console.WriteLine("source : {0}", e.Source); Console.WriteLine("stacktrace : {0}", e.StackTrace); } } } }