// 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 and SiteFilter service * to add a site filter. *

* 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/SiteFilter?wsdl
 * 
*/ public class AddSiteFilter { // SOAP Headers static final String developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; static final String developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; static final String clientId = "REPLACE WITH CLIENT'S ID"; /* The namespace used for API headers. */ private static final String apiNS="http://www.google.com/api/adsense/v2"; /** * This simple demonstration program adds a site filter. */ 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 SiteFilter service SiteFilterService siteFilterService = (new SiteFilterServiceServiceLocator()).getSiteFilterService(); // Set the SOAP headers ((Stub) siteFilterService).setHeader(apiNS, "developer_email", developerEmail); ((Stub) siteFilterService).setHeader(apiNS, "developer_password", developerPassword); ((Stub) siteFilterService).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(); // add a site filter to block all adds from www.example.com/* String[] siteFilters = new String[]{"www.example.com"}; siteFilterService.addSiteFilters(synServiceId, siteFilters); } }