Partial Class CreateAdSenseAccount
Inherits System.Web.UI.Page
Protected Sub btnCreateAccount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreateAccount.Click
CreateAdSenseAccount()
End Sub
Protected Sub chkAccept_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkAccept.CheckedChanged
btnCreateAccount.Enabled = chkAccept.Checked
End Sub
Public Sub CreateAdSenseAccount()
' Create an instance of the AdSense Accounts. You must have a web reference added to
' the URL "https://sandbox.google.com/api/adsense/v2/AccountService?wsdl" and name the
' webreference as "AdSenseAccounts"
Dim accountService As New AdSenseAccounts.AccountServiceService()
' Set the headers before you call the service method.
' Set the developer account email
accountService.developer_emailValue = New AdSenseAccounts.developer_email()
accountService.developer_emailValue.Text = New String() {"developer7@google.com"}
' Set the develoepr account password
accountService.developer_passwordValue = New AdSenseAccounts.developer_password()
accountService.developer_passwordValue.Text = New String() {"devpass"}
' Set the client Id. This will nto be used for account creation API since the ID is
' provided only after the AdSense account is successfully created.
accountService.client_idValue = New AdSenseAccounts.client_id()
accountService.client_idValue.Text = New String() {"some id"}
' Set the account to active. This is required only when you work with the 'sandbox' server.
' When you work with the live server, client will activate by following instructions
' in the client email. This step need to avaoided when you run against live server.
accountService.debug_association_typeValue = New AdSenseAccounts.debug_association_type()
accountService.debug_association_typeValue.Text = New String() {"Active"}
Dim clientEmail As String = txtClientEmail.Text ' use correct client email
Dim entityType As String = "Individual" ' Specify "Individual" or "Business"
Dim websiteUrl As String = txtUrl.Text ' Replace with your url
Dim websiteLocale As String = "en"
Dim preferredLocale As String = "en_US"
Dim emailPreference As Boolean = True
Dim AdTypes As String() = {"ContentAds", "ReferralAds"} ' ContentAds, SearchAds, ReferralAds
Dim acceptTerms As Boolean = True
Try
Dim result As AdSenseAccounts.SyndicationService_Data()
result = accountService.createAdSenseAccount(clientEmail, entityType, websiteUrl, websiteLocale, preferredLocale, emailPreference, AdTypes, acceptTerms)
For Each d As AdSenseAccounts.SyndicationService_Data In result
Response.Write("<BR>AdSense client id: " & d.id)
Response.Write("<BR>AdSense type: " & d.type)
Next
Catch ex As System.Web.Services.Protocols.SoapException
Response.Write("<font color=red><B>" & ex.Message & "</B></font>")
End Try
End Sub
End Class