#!/usr/bin/perl -w # # Copyright 2005 Google Inc. All rights reserved. use SOAP::Lite; # Demo of using Account service and SiteFilter service # to add a site filter. # SOAP Headers $developerEmail = 'REPLACE WITH DEVELOPER\'S EMAIL'; $developerPassword = 'REPLACE WITH DEVELOPER\'S PASSWORD'; $clientId = 'REPLACE WITH CLIENT\'S 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 Sitefilter connection $siteFilterWsdlUrl = "http://www.google.com/api/adsense/v2/SiteFilterService?WSDL"; my $siteFilterService = SOAP::Lite->service($siteFilterWsdlUrl); # Uncomment this line to display the XML request/response. #$accountService->on_debug( sub { print @_ } ); #$siteFilterService->on_debug( sub { print @_ } ); # Disable autotyping. $accountService->autotype(0); $siteFilterService->autotype(0); # Register a fault handler. $accountService->on_fault(\&faulthandler); $siteFilterService->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")); # Get the user's AdSense for Content syndication service ID $synServiceType = "ContentAds"; $synServiceData = $accountService->getSyndicationService($synServiceType, @headers); $synServiceId = $synServiceData->{"id"}; # Add a site filter to block all ads from www.example.com/* $siteFilters = ["www.example.com"]; $siteFilterService->addSiteFilters($synServiceId, $siteFilters, @headers); ### 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); }