#!/usr/bin/perl -w # # Copyright 2006 Google Inc. All rights reserved. use SOAP::Lite; # Demo of using the Account service and the AdSenseForSearch # service to generate a search box code snippet. # SOAP Headers $developerEmail = 'REPLACE WITH DEVELOPER\'S EMAIL'; $developerPassword = 'REPLACE WITH DEVELOPER\'S PASSWORD'; $clientId = 'partner-pub-REPLACE WITH CLIENT ID'; # The namespace used for API headers. my $namespace = "http://www.google.com/api/adsense/v2"; # Set up the Account service connection $accountWsdlUrl = "http://www.google.com/api/adsense/v2/AccountService?WSDL"; my $accountService = SOAP::Lite->service($accountWsdlUrl); # Set up the AdSenseForSearch connection $adSenseForSearchWsdlUrl = "http://www.google.com/api/adsense/v2/AdSenseForSearchService?WSDL"; my $adSenseForSearchService = SOAP::Lite->service($adSenseForSearchWsdlUrl); # Uncomment these lines to display the XML request/response. #$accountService->on_debug( sub { print @_ } ); #$adSenseForSearchService->on_debug( sub { print @_ }); # Disable autotyping. $accountService->autotype(0); $adSenseForSearchService->autotype(0); # Register a fault handler. $accountService->on_fault(\&faulthandler); $adSenseForSearchService->on_fault(\&faulthandler); my @headers = (SOAP::Header->name("developer_email")->value($developerEmail)-> uri($namespace)->prefix("impl"), SOAP::Header->name("developer_password")->value($developerPassword)-> uri($namespace)->prefix("impl"), SOAP::Header->name("client_id")->value($clientId)-> uri($namespace)->prefix("impl")); # Set the search options. $searchOptions = { "isSafeSearch" => "true", "showResultsInNewWindow" => "false" }; # Set the site properties. $siteProperties = { "encoding" => "", "locale" => "en" }; # Set the style. $searchBoxStyle = { "backgroundColor" => "#CCCCCC", "isButtonBelow" => "false", "isCustomStyle" => "false", "isLogoAbove" => "false", "logoType" => "GoogleLogo", "searchStyleName" => "Blue Sky", "textBoxLength" => "62", "textColor", "black" }; # Set the domains. $domains = ["test1.com", "test2.com"]; # Create the other parameters to generateSearchBoxCode. $country = "US"; $searchType = "GoogleSiteSearch"; $selectedDomain = ""; $channelName = ""; my $codeSnippet = $adSenseForSearchService->generateSearchBoxCode($clientId, $country, $searchType, $siteProperties, $searchOptions, $domains, $selectedDomain, $searchBoxStyle, $channelName, @headers); print "The code snippet to put on the page:" . "\n"; print $codeSnippet; ### Helper functions sub faulthandler { my ($soap, $res) = @_; my $errorMessage = "SOAP Fault: " . "Error Code " . $res->faultdetail->{"code"} . ". " . $res->faultdetail->{"message"}; if (defined $res->faultdetail->{"trigger"}) { $errorMessage .= " \"" . $res->faultdetail->{"trigger"} . "\" "; } if (defined $res->faultdetail->{"triggerDetails"}) { $errorMessage .= $res->faultdetail->{"triggerDetails"}; } die($errorMessage); }