// Copyright 2005 Google Inc. All rights reserved. import com.google.api.adsense.v2.*; import org.apache.axis.client.Stub; /** * Demo of using the Account service with Axis * to create an account. *
* 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/AccountService?wsdl **/ public class CreateAccount { /* SOAP Headers * * Note: When creating an account, the email and password * SOAP headers can be anything; for other methods, you'll * want these to be real values. */ static final String developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; static final String developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; /* The namespace used for API headers. */ private static final String apiNS="http://www.google.com/api/adsense/v2"; /** * This simple demonstration program creates an account. */ public static void main(String args[]) throws Exception { // Get Axis to give us a stub for the service AccountService accountService = (new AccountServiceServiceLocator()).getAccountService(); // Set the SOAP headers ((Stub) accountService).setHeader(apiNS, "developer_email", developerEmail); ((Stub) accountService).setHeader(apiNS, "developer_password", developerPassword); ((Stub) accountService).setHeader(apiNS, "client_id", "ignored"); // create the parameters to createAdSenseAccount String loginEmail = "users_login_here@example.com"; String entityType = "Individual"; String websiteUrl = "http://test.example.com"; String websiteLocale = "en"; String usersPreferredLocale = "en_US"; boolean emailPromotionPreferences = true; String[] synServiceTypes = {"ContentAds"}; boolean hasAcceptedTCs = true; // call createAdSenseAccount SyndicationService_Data[] synServiceData = accountService.createAdSenseAccount(loginEmail, entityType, websiteUrl, websiteLocale, usersPreferredLocale, emailPromotionPreferences, synServiceTypes, hasAcceptedTCs); // extract and print results String synServiceId = synServiceData[0].getId(); String synServiceType = synServiceData[0].getType(); System.out.println("Just created an AdSense account. This new " + "account has an associated " + synServiceType + " syndication service with id " + synServiceId + "."); } }