//Copyright 2006 Google Inc. All rights reserved. import com.google.api.adsense.v2.*; import org.apache.axis.client.Stub; /** * Demo of using the Account service and Channel service to add a * channel to an AdSense 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
 * java org.apache.axis.wsdl.WSDL2Java -p com.google.api.adsense.v2 \
 * https://www.google.com/api/adsense/v2/AdSenseForContent?wsdl
 * 
*/ public class CreateChannel { // 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 ID"; /* The namespace used for API headers. */ private static final String apiNS="http://www.google.com/api/adsense/v2"; /** * This simple demonstration program creates a new URL channel. */ public static void main(String args[]) throws Exception { // Get Axis to give us a stub for the Account 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", clientId); // Get Axis to give us a stub for the Channel service ChannelService channelService = (new ChannelServiceServiceLocator()). getChannelService(); // Set the SOAP headers ((Stub) channelService).setHeader(apiNS, "developer_email", developerEmail); ((Stub) channelService).setHeader(apiNS, "developer_password", developerPassword); ((Stub) channelService).setHeader(apiNS, "client_id", clientId); // Get the user's AdSense for Content syndication service ID SyndicationService_Data synServiceData = accountService.getSyndicationService("ContentAds"); String synServiceId = synServiceData.getId(); // Request a new channel for monitoring the URL http://www.example.com. // The value of id is ignored in the request. long id = 0; String name = "http://www.example.com"; String status = "Active"; String type = "Url"; // Make the call to createChannel and display the results. ChannelService_Data result = channelService.createChannel( new ChannelService_Data(id, name, type, status, synServiceId)); System.out.println("Created a new " + result.getType() + " channel with ID " + result.getId() + " for " + result.getName() + "."); } }