// Copyright 2006 Google Inc. All rights reserved. import com.google.api.adsense.v2.*; import org.apache.axis.client.Stub; import java.util.Calendar; import java.util.GregorianCalendar; /** * This class uses the Report service to generate AFC aggregate report. *

* com.google.api.adsense.v2 is generated via WSDl2Java, like this:
*

 * java org.apache.axis.wsdl.WSDL2Java -p com.google.api.adsense.v2 \
 * https://www.google.com/api/adsense/v2/ReportService?wsdl
 * 
*/ public class GenerateAFCAggregateReport { // SOAP Headers static final String developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; static final String developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; static final String clientId = "ca-pub-REPLACE WITH CLIENT'S ID"; /* The namespace used for API headers. */ private static final String apiNS="http://www.google.com/api/adsense/v2"; /** * This simple demonstration program generating afc report. */ public static void main(String args[]) throws Exception { // Get Axis to give us a stub for the service ReportService reportService = (new ReportServiceServiceLocator()).getReportService(); // Set the SOAP headers ((Stub) reportService).setHeader(apiNS, "developer_email", developerEmail); ((Stub) reportService).setHeader(apiNS, "developer_password", developerPassword); ((Stub) reportService).setHeader(apiNS, "client_id", clientId); AFCAggregateReport report = new AFCAggregateReport(); Calendar start = new GregorianCalendar(2005, Calendar.NOVEMBER, 11); Calendar end = new GregorianCalendar(2006, Calendar.FEBRUARY, 2); // Set the date range DateRange dateRange = new DateRange(); dateRange.setStartDate(start); dateRange.setEndDate(end); dateRange.setIsPredefined(false); dateRange.setPredefinedDateRange("AllTime"); // Set the report parameter report.setDateRange(dateRange); report.setOutputFormat("CSV_Excel"); report.setUnit("Page"); // Get the report. ReportData reportData = reportService.generateReport(report); String data = reportData.getData(); int numRows = reportData.getRowCount(); int numCols = reportData.getColumnCount(); // Print report. System.out.println("Number of rows : " + numRows); System.out.println("Number of columns : " + numCols); System.out.println("data : \n" + data); } }