AdSense API Samples
Home     Google API Samples     Download Source Code     API Reference     AdSense API Forum     AdSense API Blog    
Account Services Content Services Report Services
Partial Class AdSenseAggregateReport
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        GenerateReport()
    End Sub

    Public Sub GenerateReport()
        ' Gets and displays the preferred locale set for the specified client.  
        ' You must have a web reference added to the 
        ' URL "https://sandbox.google.com/api/adsense/v2/ReportService?wsdl" and name the 
        ' webreference as "AdSenseAccounts"
        Dim reportService As New AdSenseReports.ReportServiceService()

        ' Set the headers before you call the service method.

        ' Set the developer account email
        reportService.developer_emailValue = New AdSenseReports.developer_email()
        reportService.developer_emailValue.Text = New String() {"sandboxdeveloper@google.com"}

        ' Set the develoepr account password
        reportService.developer_passwordValue = New AdSenseReports.developer_password()
        reportService.developer_passwordValue.Text = New String() {"devpass"}

        ' Set the client Id. 
        reportService.client_idValue = New AdSenseReports.client_id()
        reportService.client_idValue.Text = New String() {txtClientID.Text}

        Try
            Dim startTime As DateTime = New DateTime(2006, 8, 1)
            Dim endTime As DateTime = New DateTime(2006, 12, 31)

            Dim dateRange As New AdSenseReports.DateRange
            dateRange.startDate = startTime
            dateRange.endDate = endTime

            dateRange.isPredefined = False

            Dim report As New AdSenseReports.AFCAggregateReport()

            report.dateRange = dateRange
            report.unit = "Page"
            report.outputFormat = "CSV_Excel"

            Dim result As AdSenseReports.ReportData = reportService.generateReport(report)

            Dim lines As String() = result.data.Split(vbLf)
            Dim rowCount As Int32 = lines.Length

            Dim str As String = "<table bgcolor=red cellpadding=5 cellspacing=1>"

            For i As Int32 = 0 To rowCount - 1
                Dim line As String = lines(i)
                str &= "<tr>"
                Dim cols As String() = line.Split(vbTab)

                For Each col As String In cols
                    str &= "<td bgcolor=white>" & col & "</td>"
                Next

                str &= "</tr>"
            Next
            str &= "</table>"

            lblData.Text = str

        Catch ex As System.Web.Services.Protocols.SoapException
            Response.Write("<font color=red><B>" & ex.Message & "</B></font>")
        End Try
    End Sub
End Class