// Copyright 2006 Google Inc. All rights reserved. import com.google.api.adsense.v2.*; import org.apache.axis.client.Stub; /** * This class uses the AdSenseForSearch service to generate a javascript * search box code snippet. In particular, it will generate Site search box. *
* 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/AdSenseForSearchService?wsdl **/ public class GenerateSearchCodeSnippet { // SOAP Headers static final String developerEmail = "REPLACE WITH DEVELOPER'S EMAIL"; static final String developerPassword = "REPLACE WITH DEVELOPER'S PASSWORD"; static final String clientId = "partner-pub-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 generates a search code snippet. */ public static void main(String args[]) throws Exception { // Get Axis to give us a stub for the "AdSenseForSearch service AdSenseForSearchService adSenseForSearchService = (new AdSenseForSearchServiceServiceLocator()).getAdSenseForSearchService(); // Set the SOAP headers ((Stub) adSenseForSearchService).setHeader(apiNS, "developer_email", developerEmail); ((Stub) adSenseForSearchService).setHeader(apiNS, "developer_password", developerPassword); ((Stub) adSenseForSearchService).setHeader(apiNS, "client_id", clientId); // Set the search options SearchOptions searchOptions = new SearchOptions(); searchOptions.setIsSafeSearch(true); searchOptions.setShowResultsInNewWindow(false); // Set the site properties SiteProperties siteProperties = new SiteProperties(); siteProperties.setLocale("en"); siteProperties.setEncoding(""); // Set the style SearchBoxStyle searchBoxStyle = new SearchBoxStyle(); searchBoxStyle.setLogoType("GoogleLogo"); searchBoxStyle.setIsLogoAbove(false); searchBoxStyle.setIsButtonBelow(false); searchBoxStyle.setBackgroundColor("#CCCCCC"); searchBoxStyle.setTextColor("black"); searchBoxStyle.setTextBoxLength(62); searchBoxStyle.setIsCustomStyle(false); searchBoxStyle.setSearchStyleName("Blue Sky"); // Set domain for site search String[] domains = {"test1.com", "test2.com"}; // Generate the search code String result = adSenseForSearchService.generateSearchBoxCode(clientId, "US", "GoogleSiteSearch", siteProperties, searchOptions, domains, "", searchBoxStyle, ""); System.out.println("The search box code snippet to put on the page:"); System.out.println(result); } }