Subscribe to Subscribers

Resources » Code Snippets » AdSense APIs

Create AdSense Account programmatically using AdSense APIs


Posted Date:     Category: AdSense APIs    
Author: Member Level: Gold    Points: 10



This VB.NET code sample shows how to create a Google AdSense account by accessing the Google AdSense APIs through the web services.

You can learn more about AdSense APIs, instructions to add web reference to Google services, and download a sample website which features many of the Google APIs.


Google AdSense API Sample code to create a new account:


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 = "http://www.dotnetspider.com/adsense" ' 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("
AdSense client id: " & d.id)
Response.Write("
AdSense type: " & d.type)
Next
Catch ex As System.Web.Services.Protocols.SoapException
Response.Write("" & ex.Message & "")
End Try


The response of createAdSenseAccount call is an array of SyndicationService_Data object. The result output in the above sample will look like the following:

AdSense client id: ca-pub-0859781803807877
AdSense type: ContentAds
AdSense client id: ca-ref-pub-0859781803807877
AdSense type: ReferralAds

Note that the above code will create an account on the Sandbox server provided by google to test and learn Google AdSense APIs. When you are ready to implement the above code in your website to offer dynamic creation of adSense accounts, you will have to change the Web Reference URL to a non sandbox URl and also get approval from Google. The sample code will work without any changes on both sandbox server as well as live server.





Did you like this resource? Share it with your friends and show your love!


Responses to "Create AdSense Account programmatically using AdSense APIs"
Author: Nishikant    20 Feb 2010Member Level: Gold   Points : 0
nice one.can also attach the c# code?


Author: Raphael Mutiso    29 Jul 2010Member Level: Bronze   Points : 0
Does google still support adsense api v2?


Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Previous Resource: Add a service to existing AdSense account
    Return to Resources
    Post New Resource
    Category: AdSense APIs


    Post resources and earn money!
     
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.